私は最近、古い角型アプリケーションのために(それほど新しい)コンポーネントを使用し始めました。私は<button/>
のような簡単なもののためにsome dumb componentsを作ろうとしています。AngularJSの片方向バインディングが動作しないようです。
何らかの理由で、片方向バインディングが機能しないようです。
(difficult-button.js
中)difficultyButton
コンポーネントに結合level
は常にundefined
を返しますが、onLevelChosen
は(difficulty-button.js
で、再び)結合options
コンポーネントは、渡されたコールバックを持っているようです。
どこの人が間違っているのか分かりますか?ここで
この問題を実証jsbinリンクである:彼らはvm.level
の値のホールドをキャッチすることができませんでしたので、クラスred
、とblue
が印加されない飽きないかhttp://jsbin.com/rixukuh/11/edit?html,js
注意してください。
また、どのボタンがクリックされても、コンソールは常にLEVEL => undefined
を出力します。より多くのコンテキストが必要な場合
FULL CODE
はここで、完全なコードです。
options.tpl.html
<div class="full-page-cover">
<div class="options-grid">
<!-- some random markup -->
<div class="buttons-grid">
<difficulty-button
level="easy"
on-level-chosen="vm.chooseDifficulty(level)" >
I'm just here for having fun!
</difficulty-button>
<!-- some more `difficulty-buttons` -->
</div>
</div>
</div>
options.js
import angular from 'angular';
import DifficultyButtonModule from './difficulty-button.js';
import template from './options.tpl.html';
class OptionsController {
constructor() { /* ... */ }
chooseDifficulty(level) { /* ... */ }
}
const OptionsModule = angular.module('options', [DifficultyButtonModule.name])
OptionsModule.component('options', {
template,
controller: OptionsController,
controllerAs: 'vm'
});
export default OptionsModule;
difficulty-button.tpl.html
<button
ng-class="[
'uk-button uk-button-large',
{
easy: 'uk-button-default',
medium: 'uk-button-primary',
hard: 'uk-button-danger'
} [ vm.level ]
]"
ng-click="vm.onLevelChosen({ level: vm.level })"
ng-transclude>
</button>
difficulty-button.js
import angular from 'angular';
import template from './difficulty-button.tpl.html';
const DifficultyButtonModule = angular.module('difficultyButton', []);
DifficultyButtonModule.component('difficultyButton', {
template,
bindings: {
level: '<',
onLevelChosen: '&'
},
controllerAs: 'vm',
transclude: true
});
export default DiffButtonModule;
あなたはフィドルを提供できますか? –
@ Gonzalo.-確か!私は1つを振ってみましょう。 – krishgopinath
@ Gonzalo.-私の編集をチェック!私はjsbinファイルを追加しました – krishgopinath