gpt4 book ai didi

javascript - Angular Directive(指令)通信

转载 作者:行者123 更新时间:2023-12-03 10:33:48 26 4
gpt4 key购买 nike

最近我在关注免费教程 https://egghead.io/lessons/angularjs-directive-communication关于指令通信及其示例。

index.html

<body ng-app="app">
<country>
<state>
<city></city>
</state>
</country>
</body>

app.js

var app = angular.module('app', []);

app.directive('country', ['', function(){
return {
controller: function() {
this.makeAnnouncement = function(message){
console.log("Country says: " + message);
};
},
restrict: 'E'
};
}]);

app.directive('state', ['', function(){
return {
controller: function() {
this.makeLaw = function(law){
console.log("Law: " + law);
};
},
restrict: 'E'
};
}]);

app.directive('city', ['', function(){
return {
restrict: 'E',
require: ["^country","^state"],
link: function($scope, iElm, iAttrs, controller) {
controller[0].makeAnnouncement("from city");
controller[1].makeLaw("Jump higher");
}
};
}]);

但它遇到了错误,错误消息 Unknown provider: Provider <- <- cityDirective 。怎么解决呢?

最佳答案

改变这个

app.directive('country', ['', function(){

到此

app.directive('country', [function(){

类似于州和城市而且,在状态指令声明中还有一个额外的 }

plnkr

关于javascript - Angular Directive(指令)通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29095895/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com