我试图将动态模板应用于我的递归指令,但它没有正常工作;可能是错误使用或不是最佳做法。
我的指示:
'use strict';
angular.module('myApp')
.directive("question", function (RecursionHelper, $http, $templateCache) {
return {
restrict: "E",
scope: {question: '=' },
templateUrl: 'views/activity.question.html',
compile: function (element) {
return RecursionHelper.compile(element, function (scope, iElement, iAttrs, controller, transcludeFn) {
$http({ method: 'GET', url: './views/answer-types/answer.' + scope.question.AnswerType + '.html', cache: true }).then(function (result) {
iElement.html(result.data).show(); // tried with element.html() (the same output)
RecursionHelper.compile(element, function (scope, iElement, iAttrs, controller, transcludeFn) { });
});
});
},
controller: 'ActivityListCtrl'
};
});
我希望html文件(例如answer.singleline.html):
{{question.Description}}
显示我的问题描述,而不是将输出作为字符串/文本返回({{question.Description}})