0
控制器:如何在Angular中從靜態指令模板訪問獨立的範圍屬性?
app.controller('MainCtrl', ['$scope', function($scope) {
$scope.temp = {
'name': 'Test'
};
}]);
模板:
<custom-field ng-model="temp.name">
<md-input-container class="addon-menu">
<label>Name</label>
<input ng-model="ngModel" type="text" ng-focus="setLastFocusedElement($event)" />
</md-input-container>
</custom-field>
指令:
app.directive('customField', function($timeout) {
return {
restrict: 'E',
scope: {
ngModel: '='
},
link: function($scope, $element, $attrs) {
console.log($scope.ngModel); // prints "test"
}
};
});
的問題是,一旦模板被渲染,我不能看到連接到input
的價值 - 這是空的,但我期望能夠正常工作,因爲在link
函數內它的打印是正確的。