我试图动态添加$ scope
app.directive('dynamic', function ($compile) {
return {
restrict: 'A',
replace: true,
link: function (scope, ele, attrs) {
scope.$watch(attrs.dynamic, function (html) {
ele.html(html);
$compile(ele.contents())(scope);
});
}
};});
和我的HTML;
<select dynamic="myOption_{{ item.RowId }}" id="select_{{ item.RowId }}" multiple class="chosen" data-ng-model="selectedOption" data-placeholder="Select" data-ng-change="ChangeTopic()"
chosen="directiveOptions"
ng-options="item.Id as item.tag for item in optionsFromQuery"
style="width:100%;">
</select>
角;
var appsx = "";
for (var i = 0; i < result.item.length; i++) {
var rowIds = parseInt(result.item[i].RowId);
appsx = '<option value="" selected>' + result.item[i].Tags + '</option>';
var controlName = 'myOption_' + rowIds;
controlName = appsx;
}
实施例;如果我尝试$ scope.myOption_100 = appsx;它正在工作,但我不能动态范围
$ scope.controlName ='myOption_'+ rowIds;那样的。
答案 0 :(得分:0)
尝试范围。$ observe(attrs.dynamic .....