javascript - I replaced $scope to a variable and now my angular application doesn't work -
i'm doing angular application , read it's practice don't use $scope. replaced variable, , data not appearing on page:
this:
observatoryapp.controller('appcontroller', function appcontroller($scope, $http){ var $scope = this; $scope.years = []; $http.get('json/years.json').then(function(response){ $scope.years = response.data; $scope.data = $scope.years[0]; });
now this:
observatoryapp.controller('appcontroller', function appcontroller($http){ var self = this; self.years = []; $http.get('json/years.json').then(function(response){ self.years = response.data; self.data = self.years[0]; });
and data not showing on index.html page:
<body ng-controller="appcontroller"> ... <select class="year form-control" ng-options="year.id year in years" ng-model="data"> </select> ... </body>
what i'm doing wrong?
i read it's practice don't use $scope
that have been in context of using controlleras
alias alternative.
unless use alias use injected $scope
assign model properties to. never var $scope = this;
Comments
Post a Comment