コンポーネントに渡されたバインディングはhtmlで動作しますが、コントローラでは未定義です。AngularJs 1.5 ES6:コントローラで定義されていないバインディング
<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 hero.html
class HeroController {
constructor() {
this.name = 'hero';
console.log(this.value); // undefined!
}
}
<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
問題を解決して使用して、APIコールの後にロードされたため、そのが定義されていないが、それはまだ定義されていない、私の値は、私は見ていないので、変更されることはありません私が覚えているように、$ onChanges –
@farhanlatheef 1.5.0を使用するポイントには$ onInitがありません。 1.5.3以上にアップグレードしてください。 – estus
$ onInitは1.5.0にあるはずです。しかし、正しい$ onChangesは1.5.3に付属しています。あなたの問題の概要を説明してくれますか? 'foo'は親コントローラの定義されたプロパティですか? – PerfectPixel