Comma Separated

angular

前端 未结 7 1056
清歌不尽
清歌不尽 2020-12-31 17:25

I have a pretty basic scenario (somewhat new to angular). I am trying to convert JSON:

[
    {\'name\': \'Nick\'},
    {\'name\': \'David\'},
    {\'name\':         


        
7条回答
  •  离开以前
    2020-12-31 18:06

    You cannot do this. Instead, use a map and join. For example:

    {{names}}

    $scope.menuItems = [ {'name': 'Nick'}, {'name': 'David'}, {'name': 'John'}, ]; $scope.$watch('menuItems', function(menuItems) { $scope.names = menuItems.map(function(item) { return item.name }).join(','); });

    This will $watch the menuItems and update the names property of the $scope whenever menuItems changes.

提交回复
热议问题