Component communication in angular 1.5

泄露秘密 提交于 2019-12-05 10:49:12

In angular 1.5 you can use require and/or property bindings (input/output) to communicate.

If you use the require property then your root component would publish an api and your child component would get a reference to the controller:

angular.module('app').component('child1', {
   bindings: {},
   require: {api: '^root'}, //your <root> component
   template: '',
   controller: controller
});

You can then use the methods of the root component in your child component:

$ctrl.api.addWatchedBook();

This is the root component controller function:

$ctrl.addWatchedBook = addWatchedBook;

function addWatchedBook(bookName){

  booksWatched.push(bookName);

}

Here is a complete architectual overview: Component Communications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!