0
我有一個指令,不幸的是,我從模板創建的調用沒有經過模板本身。爲了測試這個,我實際上創建了另一個名爲helloWorld的範圍變量,並嘗試使用該字符串並顯示它。該字符串也未顯示。這與範圍和指令模板的斷開非常混亂。下面的代碼:指令的隔離作用域函數沒有從我的模板中調用
angular.module('application.directives').directive('addSegment', function() {
return {
restrict: 'E',
scope: {
addmodel:'=',
seg:'='
},
replace: true, // Replace with the template below
transclude: true,
link: function(scope, element, attrs) {
scope.helloWorld = "hello Worldly things";
scope.selectedsegment = function(s,add){
console.log("inside selectedsegment");
if(typeof add.selectedSegments === "undefined"){
add.selectedSegments = [];
}
var ind = add.selectedSegments.indexOf(s.id);
if(ind === -1){
add.selectedSegments.push(s.id);
}else{
add.selectedSegments.splice(ind,1);
}
}
},
template: "<div ng-repeat='segment in seg|filter:{status:0}'><label>{{helloWorld}}</label><input type='checkbox' ng-click='selectedsegment(segment,addmodel)'/></div>"
};
});
電話從我的html:
<add-segment addModel='addGainCreator' seg='segments'></add-segment>
上解決此問題的任何幫助,將不勝感激。 謝謝
顯示如何在'seg'數組中使用指令和數據? ng-repeat'實際上可以過濾掉所有的東西。 –
所以我創建了由三件事組成的ngmodels對象。標題,說明和段數組。段數組被顯示爲反對用戶點擊。在點擊一個文本框後,該數組將被填充點擊段的複選框的ID或刪除,如果它已經存在。有趣的是,我的細分數據將顯示,但我新設置的範圍內沒有任何內容正在處理中。 – user2977578
哪裏的'ng-model'在......代碼中沒有顯示的代碼?聽起來就像你打破了在ng模型中不使用對象的黃金法則。創建一個演示,複製問題 – charlietfl