Modifying objects within Angular Scope inside ng-repeat

后端 未结 2 700
南方客
南方客 2020-12-10 06:33

I\'m creating a form in HTML using ng-repeat to generate the form elements from an object in the scope. I also use that object to generate other elements outside of the ng-

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-10 07:19

    try this:

        angular.module('App', []);
    
    function Ctrl($scope) {
        $scope.test = [
            {label:"a", value:"abc"},
            {label:"b", value:"def"}
        ]
    }
    

    and

    {{o.value}}

    {{test[0].value}}

    {{test[1].value}}

    Angularjs uses the fact that objects are passed by reference. So, if you pass a object to a function and change the object inside the function, the object outside also changes. Look at this updated JSFiddle

提交回复
热议问题