Javascript 角度传感器中指令间通信抛出错误
如何将控制器公开给另一个指令。最后,我希望在指令之间进行通信。使用slideshow指令$compile对象。同时,让响应页面指令更新幻灯片放映指令。首先,我需要他们之间的沟通 错误如下:Javascript 角度传感器中指令间通信抛出错误,javascript,angularjs,Javascript,Angularjs,如何将控制器公开给另一个指令。最后,我希望在指令之间进行通信。使用slideshow指令$compile对象。同时,让响应页面指令更新幻灯片放映指令。首先,我需要他们之间的沟通 错误如下: Error: [$compile:ctreq] Controller 'slideshow', required by directive 'responsivePage', can't be found! html <div ng-app="myApp" id="weekly"> <
Error: [$compile:ctreq] Controller 'slideshow', required by directive 'responsivePage', can't be found!
html
<div ng-app="myApp" id="weekly">
<script type="text/ng-template" id="template1.html">
<div class="weekly-viewport" responsive-page >
<ul class="page-collection">
<li class="page-layout" ng-repeat="page in pages">
<ul class="page shop-local-page">
<li class="imageurl"><img ng-src="{{page.imageurl}}" alt="" /></li>
</ul>
</li>
</ul>
</div>
</script>
<div ng-controller="MainCtrl" class="inner-weekly">
<slideshow></slideshow>
</div>
</div>
我希望我能帮助你
可以直接使用
myApp.directive('responsivePage', function(){
return{
restrict: 'A',
link: function postLink(scope, element, attrs, slideshowCtrl) {
console.log(scope.adPageData);
console.log(scope.adpageLength);
var targetRatio = 0.8419689;
var pageCollectionWidth = angular.element(document.querySelector('.page-collection'))[0].offsetWidth;
var pageCollectionHeight = angular.element(document.querySelector('.page-collection'))[0].offsetHeight;
scope.properPageWidth = pageCollectionHeight*targetRatio;
console.log();
}
}
});
另一种使用方式
myApp.directive('slideshow', function($window){
return {
restrict: 'E',
name:'aa_aa',//controller alias
templateUrl: 'template1.html',
controller: function($scope, Pages) {
this.x ='x'
},
link: function(scope, element, attrs) {
}
};
})
.directive('responsivePage', function(){
return{
restrict: 'A',
require: '^aa_aa',
link: function(scope, element, attrs, $controller) {
console.log($controller)
}
}
});
尝试
要求:“^slideshow”
(注意^
)在其祖先上查找slideshow
控制器
从
^前缀表示此指令在上搜索控制器
它的父级(没有^prefix,该指令将查找
控制器(仅在其自身元素上)
请尝试
require:'^slideshow'
(注意^
)也查找其祖先。将^in放入后,它停止抛出错误@MarcKline。老实说,我只想访问$scope.adPageData.抱歉。是的,我误读了你的密码。我没有看到响应页面
包含在幻灯片
@KhanhTO的模板中。如果你放一个标签,把答案放下来,我会把它标记为正确。
myApp.directive('slideshow', function($window){
return {
restrict: 'E',
name:'aa_aa',//controller alias
templateUrl: 'template1.html',
controller: function($scope, Pages) {
this.x ='x'
},
link: function(scope, element, attrs) {
}
};
})
.directive('responsivePage', function(){
return{
restrict: 'A',
require: '^aa_aa',
link: function(scope, element, attrs, $controller) {
console.log($controller)
}
}
});