我有一個動態創建輸入標籤的指令。我需要獲取有關更改事件的已創建輸入的值。取而代之的是controller
中參數$scope
上的name
屬性未定義。如何在指令控制器中獲取ng-model
值?Angularjs:模型綁定
module.directive('createControl', function($compile, $timeout){
return {
transclude: true,
restrict: 'A',
scope: {
name: '=name'
},
link: function(scope, element, attrs){
// simplified version
tag = '<input type="text" ng-model="name"/>'
element.append(html);
controller: function($scope){
// In the controller I need to get value of created input on change event
console.log($scope);
}
}
});
你可以分享與HTML指令聲明完整代碼.PLS成立了plunker代碼或的jsfiddle – 2013-05-09 06:41:23