1
我的問題是我的指令不顯示模板。我通過「$ sce.trustAsHtml(taskDirective)」和「$ compile(taskDirective)($ scope)」在我的控制器中添加了具有特定名稱的html標記 。調用指令 內的控制器功能。但模板沒有顯示出來。角度指令不會渲染模板,在控制器中動態添加html後
進出口使用的$ stateProvider,它調用「TaskDetailCtrl」有一定的HTML。
有人可以幫忙嗎?
謝謝+
控制器:
app.controller("TaskDetailCtrl", function ($scope, $state, $stateParams, $sce, $compile) {
cur_task = $stateParams.newTask;
$scope.title = cur_task.title;
var taskDirective = "<" + cur_task.type + "taskdirective" + "></" + cur_task.type + "taskdirective" + ">";
$scope.showTask = $sce.trustAsHtml(taskDirective);
$compile(taskDirective)($scope);
});
指令:
app.directive('clicktaskdirective', function() {
return {
restrict: 'E',
template: '<ion-content style="padding: 20px;" class="text-center"><br><br><h1>{{taskTitle}}</h1><br><br><h4>{{taskText}}</h4><br><br><button class="button button-block button-stable" ng-click="start()">Stimmt!</button></ion-content>',
controller: function ($scope, $state, $stateParams) {
console.log("This is showing up!")
}
}
});
HTML:
<div ng-bind-html="showTask"></div>
非常感謝你,那定了! 所以也許更好的解決方案是使用stateProvider來執行不同的任務,而不是隻使用一個具有不同指令的任務狀態...... –