using databinding within ng-repeat

72 views Asked by At

My problem scenario is that I already got one name dynamically through controller and now what I am trying to do is to bind that name within my ng-repeat. How can I do that? Please give me some suggestion. Is there any way to get that dynamic name in ngrepeat?

An example:

<div ng-controller="bookCtrl">
    <div ng-repeat="tag in {{a}}.tags">
        <input type="text" ng-model="tag"/>
    </div>

    My tags are <b>really</b>: {{ book.tags }}
</div>

angular.module('myApp', [])
.controller('bookCtrl', function($scope) {
    $scope.a=book;
    $scope.book = {
        name: 'A Game of Thrones',
        tags: [
            'Tyrion',
            'John Snow',
            'Arya',
            'Sean Bean'
        ]
    };
});

Here's a Fiddle link.

1

There are 1 answers

3
Kalhan.Toress On BEST ANSWER

please check this

fiddle

controller('bookCtrl', function($scope) {

$scope.book = {
    name: 'A Game of Thrones',
    tags: [
        'Tyrion',
        'John Snow',
        'Arya',
        'Sean Bean'
    ]
};
$scope.a=$scope.book;

});

<div ng-repeat="tag in a.tags">
    <input type="text" ng-model="tag"/>
</div>