컨트롤러 :각도에서 정적 지시어 템플릿에서 격리 된 스코프 속성에 액세스하는 방법?
이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
기능이 제대로 인쇄 되었기 때문에 작품을 기대하고 있습니다.