我在我的角度模塊中有一個自定義指令,我想動態地將其插入到我的視圖中,同時包含控制器內部函數的不同信息的多個實例也在模塊中..這是如何完成的?對於例子緣故here is a sample fiddle用來告訴我如何做到這一點如何從角度控制器插入指令到視圖中?
var myApp = angular.module('myApp',[]);
myApp.directive('myDirective', function() {
return {
restrict: "E",
transclude: true,
template: "<div><h4>Hello, World!</h4></div>"
}
});
function MyCtrl($scope) {
$scope.insertDir = function(){
//????
}
}
@AlexScott的視圖,不確定爲什麼你沒有將此標記爲答案。 'ng-repeat'只是視圖決定如何渲染的一種方式。它可以很容易地使用'ng-if =「values [N]!== undefined」'並且將指令灑在任何你想要的地方。 – 2014-10-06 15:48:56
是的,我不是故意的 - 道歉 – alsco77 2014-10-07 08:04:43