javascript - $scope doesnt update on change -
i trying update view on button click, doing wrong. console showing array want be, ng-repeat list not updating.
html:
<body ng-app="myapp"> <div layout="row" ng-controller="lekovicontroller"> <md-content md-scroll-y flex class="lista_lekova_layout"> <md-list> <md-list-item ng-repeat="lek in lekovi | filter:search"> <p ng-click="prikaz(lek)">{{lek.naziv}}</p> </md-list-item> </md-list> <button ng-click="loadmore()">ucitaj jos</button> </md-content> </div> </body>
js:
var app = angular.module('myapp', [ 'lbservices', 'ui.router', 'ngresource', 'ngmaterial', 'ngmdicons', 'ngroute' ]); app.controller('lekovicontroller', ['$scope', '$mdsidenav', 'lekovi', 'oblicileka', function($scope, $mdsidenav, lekovi, oblicileka) { $scope.ucitano = false; $scope.trenutniid = 0; var lek = []; $scope.lekovi = lekovi.find({ filter: { where: { lekid: {between: [1, 100]} } } }, function(){ $scope.ucitano = true; }); $scope.loadmore = function() { $scope.trenutniid = $scope.lekovi.length + 100; lek = lekovi.find({ filter: { where: { lekid: {between: [$scope.lekovi.length, $scope.trenutniid]} } } }, function(){ for(i = 0; i<lek.length; i++){ $scope.lekovi.push(lek[i]); } console.log($scope.lekovi); }); };
i trying work $scope.$apply() didn't work either.
btw. did declare variable 'lek'? shouldn't used parameter of success callback function?
$scope.loadmore = function() { $scope.trenutniid = $scope.lekovi.length + 100; lekovi.find({ filter: { where: { lekid: {between: [$scope.lekovi.length, $scope.trenutniid]} } } }, function(lek){ // declare 'lek' function parameter for(i = 0; i<lek.length; i++){ $scope.lekovi.push(lek[i]); } console.log($scope.lekovi); });
Comments
Post a Comment