简体   繁体   中英

Using ng-repeat in directive with isolated scope

ng-repeat inside a directive with isolated scope is not picking up the property that's passed through '=' binding.

HTML:

<body ng-controller="myCtrl">
    <div my-directive list="users">
        <ul>
            <li ng-repeat="item in list">
                {{item.name}}
            </li>
        </ul>
    </div>
</body>

JS:

var app = angular.module('myApp', []);

app.controller('myCtrl', function ($scope) {
    $scope.users = [
        { name: 'John Doe'},
        { name: 'Jane Doe' },
        { name: 'Jesse Doe' }
    ];
});

app.directive('myDirective', [function() {
    return {
        restrict: 'A',
        scope: {
            list: '='
        },
        link: function(scope, element, attrs) {

        }
    }
}]);

Above code works fine with angular 1.0.8: http://jsfiddle.net/shazmoh/4DN39/7/

but not with angular 1.2.14: http://jsfiddle.net/shazmoh/4DN39/6/

What got changed with '1.2.x' that I'm missing?

From the migration to 1.2 guide :

Isolate scope only exposed to directives with scope property
Directives without isolate scope do not get the isolate scope from an isolate directive on the same element. If your code depends on this behavior (non-isolate directive needs to access state from within the isolate scope), change the isolate directive to use scope locals to pass these explicitly.

So, with > 1.2.0, isolated directives are completely isolated .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM