have two different controllers, one for language, langCntl, and one for words, wordCntl.
in the wordCntl record there is an attribute called ln. ln is displayed in the form using ng-select, with ngOptions based on records in the langCntl controller.
how do I make the select for ln refresh in wordCntl when records change in langCntl?
langMod.js
var langMod = angular.module('langMod', ['ngResource']);
langMod.controller('langCntl',function($scope,$http) {
$scope.langs = [];
$scope.reset = function() {
$http.get( '/lang.jsn').success( function(data) {
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' >
<body>
<ng-form ngForm='abc' ng-controller='wordCntl' >
<select ng-model="rcd.ln" ng-options="c.lang as c.name for c in langs">
</ng-form>
</body>
</html>
What interesting (to me):
- after
langCntl.langschanges,wordCntl.langsremains an empty array. - in the
ngoptions, is there a way to directly use the records inlangCntl?