使用Angular 1.5和最新ui-router版本的嵌套组件

时间:2016-07-28 20:09:30

标签: angularjs angular-ui-router

我试图使用新的1.5路由器和角度组件接吻路线,但我出现了嵌套组件的问题

.state('custom', {
    abstract: true,
    url: '/custom,
    component: 'custom'
})
    .state('custom.children', {
        url: '/children',
        component: 'customChildren'
    })

customChildren组件有以下模板:

<p>Lorem Ipsum</p>
<div>
    <h1>My Title</h1>
    <div ui-view class='settings-content' 
        custom-children-attr='$ctrl.childrenValue'>
    </div>
</div>

custom组件:

class CustomController {
  constructor() {
    ...
  }

  $onInit() {
      this.childrenValue = 'test';
  }

  $onChanges(changes) {
    ...
  }
}

angular
  .module('app')
  .component('custom', {
    templateUrl: 'custom.html',
    controller: CustomController
  });

customSon就是这样:

class CustomChildrenController {
    constructor(...) {
        ...
    }

    $onInit() {
        ...
    }

    $onChanges(changes) {
        ...
    }
}

angular
    .module('app')
    .component('customChildren', {
        templateUrl: 'custom-children.html',
        controller: CustomChildrenController,
        bindings: {
            customChildrenAttr: '<'
        }
    });

当我转到/custom/children时,我无法获得customChildrenAttr的值。我如何获得customChildrenAttr绑定?我尝试过决心和其他事情,但我不能让它发挥作用。

0 个答案:

没有答案