2017-02-22 33 views
1

我有一個包含多個嵌套組件的Angular 1.5系統。我現在需要使用指令(這需要是一個屬性),它將嵌入到組件中。父組件中的角1.x子指令調用方法組件

如何從子指令中調用父組件中的函數?以某種方式在父組件中暴露方法的正確語法是什麼,以便子指令中的事件可以調用它?

+0

通過'require'使用。 [RTM](https://docs.angularjs.org/guide/component#intercomponent-communication)。另見https://stackoverflow.com/questions/35293680/using-require-in-angular-component。 – estus

+0

[AngularJS從子控制器訪問父範圍]的可能副本(http://stackoverflow.com/questions/21453697/angularjs-access-parent-scope-from-child-controller) –

回答

0

可以在子元素 $scope.$emit('EventName', attrObject);$rootScope.$broadcast('EventName', attrObject);

而且在父控制器

$scope.$on('EventName', function(event, attrObject){ 
//your code calling function you want to use 
} 
相關問題