ディレクティブによって作成されたモデルにアクセスする必要があり、同時にディレクティブで属性を取得する必要があります。
JS:
module.directive('createControl', function($compile, $timeout){
return {
scope: {
name: '=Name' // Dynamically created ng-model in the directive element
},
link: function(scope, element, attrs){
attrs.$observe('createControl', function(){
attrs.createControl //is empty if scope is an object, otherwise it is passed from html attribute
}
}
HTML:
<div class="control-group" ng-repeat="x in selectedControls">
<div create-control="{{ x }}"></div>
</div>
オブジェクトscope
として定義されている場合attrs
は空です。それ以外の場合は、html から渡された値です。
この動作の原因は何ですか? 渡された属性とモデルにアクセスするにはどうすればよいですか?