[英]Angular js Error: [$compile:ctreq] Controller xxxx, required by directive yyyy, can't be found
I already multiple topics on stackoverflow about this error but I always don't understand the problem in my context. 我已经在关于这个错误的stackoverflow上有多个话题,但是我始终无法理解我的问题。
I have this template: 我有这个模板:
<div class="progress">
<div class="progress-bar"
data-toggle="tooltip"
title="Parts offertes : {{ '{{ gift.gived_parts}}' }} / {{ '{{ gift.number_of_parts }}' }}"
data-bar="gived"
>
<span ng-class="{true:'op7', false:''}[gift.percent_done > 0 && gift.percent_done < 20]">
{{ '{{ gift.gived_parts}}' }}
</span>
</div>
<div class="progress-bar progress-bar-danger progress-bar-striped progress-bar-animate active op7"
data-toggle="tooltip"
title="Parts réservées : {{ '{{ gift.total_reserved}}' }} / {{ '{{ gift.number_of_parts }}' }}"
data-bar="reserved">
</div>
For this directive: 对于此指令:
app.directive('progressBarD', function() {
return {
restrict: 'E',
templateUrl: rootUrl + '/directive/progressBar',
scope: {
gift: '=gift'
},
link: function ($scope, $elem, attrs) {
var bars = $elem.find(".progress-bar");
bars.each(function() {
var bar = $(this);
var percent = (bar.context.dataset.bar === "gived")
? $scope.gift.percent_done
: $scope.gift.percent_reserved;
if (($().appear) && isMobileDevice === false && (bars.hasClass("no-anim") === false) ) {
bar.appear(function () {
bar.addClass("progress-bar-animate").css("width", percent + "%");
}, {accY: -150} );
} else {
bar.css("width", percent + "%");
}
});
}
};
});
And here is the call of the directive: 这是指令的调用:
<progress-bar-d gift="gift"></progress-bar-d>
During the execution, I obtain this error: 在执行期间,我得到此错误:
Error: [$compile:ctreq] Controller 'progress', required by directive 'bar', can't be found!
http://errors.angularjs.org/1.3.15/$compile/ctreq?p0=progress&p1=bar
at angular.js:63
at getControllers (angular.js:7583)
at nodeLinkFn (angular.js:7772)
at angular.js:7998
at processQueue (angular.js:13248)
at angular.js:13264
at Scope.$get.Scope.$eval (angular.js:14466)
at Scope.$get.Scope.$digest (angular.js:14282)
at Scope.scopePrototype.$digest (hint.js:1468)
at Scope.$get.Scope.$apply (angular.js:14571)
On the screen, the link function look to work, but at the end, the inside the first desapear when gift.percent_done is different of 0. 在屏幕上,链接功能看起来可以工作,但是最后,当gift.percent_done的值不等于0时,第一次出现内部缺失。
Could you explain me why I have this angular error ? 你能解释一下为什么我有这个角度误差吗? Do the deletion of the span is the same problem ?
删除跨度是否是同样的问题?
Finally I found the problem. 终于我找到了问题。
In the anguluar directive I change bar.context.dataset.bar and it work. 在anguluar指令中,我更改了bar.context.dataset.bar并且它起作用。 I don't know why that was not well interpreted but now it work.
我不知道为什么不能很好地解释它,但是现在可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.