1

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):

  1. after langCntl.langs changes, wordCntl.langs remains an empty array.
  2. in the ngoptions, is there a way to directly use the records in langCntl?

1 Answer 1

2

Reference angualrjs sdk: $broadcast(name, args)

Dispatches an event name downwards to all child scopes (and their children) notifying the registered ng.$rootScope.Scope#$on listeners.

The event life cycle starts at the scope on which $broadcast was called. All listeners listening for name event on this scope get notified. Afterwards, the event propagates to all direct and indirect scopes of the current scope and calls all registered listeners along the way. The event cannot be canceled.

Sign up to request clarification or add additional context in comments.

3 Comments

if you post something from doc , wrap it with '>' to show that its not your words
that's cool, but what about the nitty gritty of getting the select to refresh?
you can add a ng-change event lisentner to you select element.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.