【发布时间】:2016-07-13 12:23:07
【问题描述】:
我对来自另一个人的指令访问有疑问,代码如下
app.module('myApp', [])
.directive('vikiQues', ['$http', '$compile', function($http, $compile){
return {
restrict : 'E',
scope : true,
controller : [
function (){
}
],
link : function(scope, iElement, iAttrs){
$http.get('getOutside/1')
.then(function(data){
iElement.html($compile($(data.data))(scope));
/*scope.addThere.find('div.please-wait').remove();
scope.questionList.push({
text : '',
options : []
});*/
});
}
};
}]).directive('vikiOption', ['$http', '$compile', function ($http, $compile) {
return {
restrict: 'E',
scope : true,
require : '^vikiQues',
link: function (scope, iElement, iAttrs, vikiQuesCtrl) {
$http.get('getInside/1')
.then(function(data){
var _ = $(data.data);
scope._opt = false;
iElement.html($compile(_)(scope));
if ( scope.$parent.questionList[scope.$parent.totalQuestionCount-1].options.length > 2)
_opt = true;
scope.now = {
id : scope.$parent.questionList[scope.$parent.totalQuestionCount-1].options.length,
char : '',
text : '',
image : '',
removeable : scope._opt,
};
ques.now.options.push(scope.now);
});
}
};
}]);
我每次都收到这个错误:angular.min.js:117 Error: [$compile:ctreq] http://errors.angularjs.org/1.5.7/$compile/ctreq?p0=vikiQues&p1=vikiOption
那里有什么问题?
html代码:
0">
viki-ques 和 viki-option 是来自 php 的模板。
如果我删除
iElement.html($compile($(data.data))(范围));
代码,我不能得到错误。我想我错了。 ithink $compile 或 scope 提供此错误。 (帮助)
【问题讨论】:
-
我从 php 获得一个问题模板并将 html 设置为 viki-ques 元素并从中获得一些选项再次php并将html设置为viki-option ...够了吗? -
信息不足,无法提供帮助。用问题创建演示,然后很容易找出问题。
标签: angularjs angularjs-directive angularjs-scope