angularjs - Angular Service "undefined" after first run -


so readingcontroller calls getromanization in main body first time , in turn calls romanize factory service (shown below controller). works fine fist time second time when round when getromanization called @ end of checkromanization romanize service comes undefined in chrome. happens romanize service? why run once?

please me have been stuck ages.

var readingcontroller = function ($scope, romanize){     $scope.getromanization = function(romanize){         $scope.currentmaterial = $scope.sections[$scope.sectionnumber].tutorials[$scope.tutorialnumber].material[$scope.questionnumber];         romanize.get($scope.currentmaterial).then(function(d){             $scope.romanized = d;         });          $scope.$apply();     };     $scope.getromanization(romanize);     $scope.$apply();     $scope.checkromanization = function(userromanization){         if ($scope.romanized === userromanization){             $scope.questionnumber++;             $scope.getromanization();         };     } }  app.factory('romanize', ['$http', 'position', function($http, position){     return{       get: function(query){             var url= position.sections[position.sectionnumber].romanizeservice + "?korean=" + query;             var promise = $http.get(url).then(function(d) {                 var parts = $(d.data).find("span");                 var array = [];                 (var x = 0; x<parts.length; x++){                     array.push(parts[x].title);                 }                 var result = array.join("");                 return result;             });             return promise;         }     }; }]); 

your second call getromanize missing service name argument

$scope.checkromanization = function(userromanization){     if ($scope.romanized === userromanization){         $scope.questionnumber++;         $scope.getromanization(romanize);     }; }; 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -