我有一个简单的父子控制器设置,我试图让我的子控制器调用父控制器中的函数:
HTML:
<div ng-controller="Parent>
<p ng-hide="ribbonHide">{{ribbonMessage}}</p>
<div ng-controller="Child">
</div>
</div>
父.js:
app.controller('Parent', function($scope, $timeout) {
$scope.searchRibbon = function() {
return {
default : function() {
$scope.ribbonMessage = 'Welcome';
$scope.ribbonHide = false;
},
clearMessage: function() {
$scope.ribbonMessage = '';
},
hide: function() {
$scope.ribbonHide = true;
},
autoRemove: function() {
$timeout(function() {
$scope.searchRibbon.hide();
$timeout(function() {
$scope.searchRibbon.clearMessage();
}, 500);
}, 5000);
}
}
}
});
Child.js
app.controller('Child', function($scope, $timeout) {
$scope.$parent.searchRibbon.autoRemove();
});
有了上述内容,我得到了错误:
TypeError: $scope.$parent.searchRibbon.autoRemove is not a function
谢谢