传递给组件的绑定在 html 中工作,但在控制器中未定义。
<hero value="foo"></hero>
hero.component.js
import template from './hero.html';
import controller from './hero.controller';
let heroComponent = {
restrict: 'E',
bindings: {
value: '@'
},
template,
controller
};
HeroController.js
class HeroController {
constructor() {
this.name = 'hero';
console.log(this.value); // undefined!
}
}
英雄.html
<section class="hero">
<h1>AngularJs ES6 Example</h1>
<!-- Value is works within template -->
<h3>You can find me inside {{ $ctrl.name }}.html {{ $ctrl.value }}</h3>
</section>
我正在使用角度版本1.5.0