Automatically return data after selecting an item in AngularJS -


for school i'm making exercise.

the exercise follows. when school subject selected must automatically return teacher of school subject. required make use of controller.

now tried make , , thought have solution, unfortunately not work , have no idea why.

does see goes wrong ?

 <div ng-app="subjectapp">     <div ng-controller="teachercontroller">         choose school subject:         <select name="repeatselect" id="repeatselect" ng-model="data.repeatselect">             <option ng-repeat="option in data.availableoptions" value="{{option.subject}}">{{option.subject}}</option>         </select>         <br>         have chosen, {{data.repeatselect}} given {{data.teacher}}.     </div>     <hr> </div> <script>     var subjectapp = angular.module("subjectapp", []);     subjectapp.controller('teachercontroller', function ($scope) {         $scope.data = {             repeatselect: null,             availableoptions: [                 {subject: "pev", teacher: "a teacher name1"},                 {subject: "wh", teacher: "a teacher name2"},                 {subject: "app", teacher: "a teacher name3"},                 {subject: "asp", teacher: "a teacher name4"},                 {subject: "php", teacher: "a teacher name5"},                 {subject: "csp-3", teacher: "a teacher name6"},                 {subject: "cisco-p", teacher: "a teacher name7"}             ]         };     }); </script> 

regards jens

something should works:

var subjectapp = angular.module("subjectapp", []);  subjectapp.controller('teachercontroller', function ($scope) {    $scope.data = {      optindex: null,      availableoptions: [        {subject: "pev", teacher: "a teacher name1"},        {subject: "wh", teacher: "a teacher name2"},        {subject: "app", teacher: "a teacher name3"},        {subject: "asp", teacher: "a teacher name4"},        {subject: "php", teacher: "a teacher name5"},        {subject: "csp-3", teacher: "a teacher name6"},        {subject: "cisco-p", teacher: "a teacher name7"}      ]    };  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>    <div ng-app="subjectapp">      <div ng-controller="teachercontroller">          choose school subject:          <select name="repeatselect" id="repeatselect" ng-model="data.optindex">              <option ng-repeat="option in data.availableoptions track $index" value="{{$index}}">{{option.subject}}</option>          </select>          <br>          <span ng-if="data.optindex != null">              have chosen, {{data.availableoptions[data.optindex].subject}} given {{data.availableoptions[data.optindex].teacher}}.          </span>      </div>      <hr>  </div>


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -