Angularjs 访问子指令函数的父指令
假设您有两条指令:Angularjs 访问子指令函数的父指令,angularjs,angularjs-directive,Angularjs,Angularjs Directive,假设您有两条指令: <navigation-extended> <navigation /> </navigation-extended> 导航扩展html模板使用div上的transclude属性插入基本导航。除此之外,导航扩展还包含额外的html(导航控件) 从父指令内部访问子功能的最佳方式是什么 我尝试过的事情: -require->使用此选项,我可以从内部导航访问导航扩展方法,但不能通过其他方式访问我认为实现这一点的最佳方法是使用$br
<navigation-extended>
<navigation />
</navigation-extended>
导航扩展html模板使用div上的transclude属性插入基本导航。除此之外,导航扩展还包含额外的html(导航控件)
从父指令内部访问子功能的最佳方式是什么
我尝试过的事情:
-require->使用此选项,我可以从内部导航访问导航扩展方法,但不能通过其他方式访问我认为实现这一点的最佳方法是使用
$broadcast
在父指令中触发事件,并在子指令中使用$on
处理它,有关此问题的更多信息,请查看此答案请尝试此简单广播
它会给你价值
function firstCtrl($scope)
{
$scope.$broadcast('someEvent', [1,2,3]);
}
function secondCtrl($scope)
{
$scope.$on('someEvent', function(event, mass) { console.log(mass); });
}