には 2 つの異なるコントローラーがあり、1 つは言語用、langCntlもう 1 つは単語用wordCntlです。
レコードにwordCntlは という属性がありますln。 コントローラ内のレコードに基づいて、 をln使用してフォームに表示されます。ng-selectngOptionslangCntl
でレコードが変更されたときselectにln更新するにはどうすればよいですか?wordCntllangCntl
langMod.js
var langMod = angular.module('langMod', ['ngResource']);
langMod.controller('langCntl',function($scope,$http) {
$scope.langs = [];
$scope.reset = 関数() {
$http.get( '/lang.jsn').success( 関数(データ) {
console.log( 'http.success: data='+data );
$scope.langs = angular.copy($scope.origs);
});
};
$scope.reset();
});
langMod.controller('wordCntl',function($scope) {
var langElem = document.querySelector("[ng-controller='langCntl']");
$scope.langs = angular.element(langElem)).scope().langs;
$scope.rcd = { ln: 'en', word: '?' };
});
index.html
<html lang='en' ng-app='langMod' >
<本体>
<ng-form ngForm='abc' ng-controller='wordCntl' >
<select ng-model="rcd.ln" ng-options="c.lang as c.name for c in langs">
</ng-フォーム>
</body>
</html>
(私にとって)興味深いこと:
langCntl.langs変更後wordCntl.langs、空の配列のままです。- の
ngoptionsレコードを直接使用する方法はありlangCntlますか?