我需要实现两个独立组件之间的组件通信。我使用了 require 关键字,但它会引发错误
错误:$compile:ctreq 缺少
指令“ctwo”所需的控制器“cone”,找不到!
这是我的代码
angular.module("app", [])
.component('cone', {
template: '<p>Component one</p>',
controller: function() {
console.log("component one loaded")
this.fone = function() {
console.log("component one function one")
}
}
})
.component('ctwo', {
template: '<p>Component two</p>',
controller: function() {
console.log("component two loaded")
},
require: {
cone: 'cone'
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js"></script>
<div ng-app="app">
<cone></cone>
<ctwo></ctwo>
</div>