最初の角度コンポーネントを ngRoute でまとめようとしていますが、これまでのところ、データを解決できません。構成:
.when('/myfirstcomponent', {
template: '<myfirstcomponent claimKeys="$resolve.claimKeys"></myfirstcomponent>',
resolve: {
claimKeys: ['$http', function($http) {
$http.get('server/claimkeys.json').then((response) => {
var claimKeys = response.data.DATASET.TABLE;
return claimKeys;
});
}]
}
})
成分:
.component('myfirstcomponent', {
bindings: {
'claimKeys': '@'
},
templateUrl: 'components/component.html',
controller: [function() {
this.$onInit = function() {
var vm = this;
console.log(vm.claimKeys);
};
}]
コンポーネントの html には、ランダムなテキストを含む ap 要素が含まれているだけです。
デバッグ中にデータを取得していることがわかりますが、コンポーネントコントローラーでアクセスできません...
編集:以下の受け入れられた回答のおかげで、私は問題を解決しました。非同期呼び出しの問題とは何の関係もありませんでしたが、ルートとコンポーネントをどのように定義したかが問題でした。修正については、以下のコードを参照してください。再度、感謝します。