Answer the question
In order to leave comments, you need to log in
ng-options and ng-model in angularjs?
There is markup
{{SelectedSemester}} -тут всё хорошо отображается
<select ng-model="SelectedSemester" ng-change="" ng-options="semester.Id as semester.Name for semester in DataService.GET_SemestersList()">
<button ng-click="group_create_show()">показать</button>
$scope.group_create_show= function() {
alert($scope.SelectedSemester) // а здесь не выводится пробовал $scope.SelectedSemester.Id
}
Answer the question
In order to leave comments, you need to log in
This is the most common Angular beginner mistake. Scopes cannot inherit scalars. Something a little higher in the hierarchy most likely created its own scope, and its ancestor is in the controller.
There are two solutions:
- use storage objects ala data. SelectedSemester
- don't use the scope in the controller and use the controllerAs syntax, then everything will be fine since the controller will be scoped by alias and since the controller is an object passed by reference, the values will be inherited.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question