我已经创建了一个指令pgPaginator:
function PaginatorDirective() {
return {
restrict: 'E',
require: 'ngModel',
templateUrl: 'paginator.html',
scope: {
ngModel: '=',
},
};
}
// ...
.directive('pgPaginator', PaginatorDirective)
paginator.html:
<input pg-paginator-page />
<select pg-paginator-perpage ng-model="ngModel.perpage" ng-options="option for option in ngModel.perpageOptions"></select>
<br />
{{ngModel}}
<br />
{{ngModel.page}}
我尝试创建另一个使用pgPaginator范围的指令pg-paginator-page:
.directive('pgPaginatorPage', function() {
return {
restrict: 'A',
replace: true,
template: '<input ng-model="ngModel.page" type="number" />',
link: function(scope, element, attrs) {
console.log(scope)
},
}
})
但是当我创建这个指令时,双向绑定被破坏了:http://embed.plnkr.co/h85hAk/preview
我做错了什么?