FAQ Database Discussion Community


ng-Repeat returning undefined within $scope.$watchCollection

angularjs,ng-repeat,ng-init
When I console.log(result) on line 5, it returns just fine. The console.log($scope.notes) on line 11 returns undefined. Any ideas? Here is my controller: $scope.$watchCollection = (['parent_id', 'parent_type'], function(){ $scope.loadNotes = function(){ $http.get('/api/notes/' + $scope.parent_id + "/" + $scope.parent_type).success(function(result){ console.log(result); $scope.notes = result; return result; }); } $scope.notes = $scope.loadNotes(); console.log($scope.notes);...

ng-init with words in AngularJS

jquery,angularjs,ng-init
I am trying to set if the new item being created is a service or a product. I want by default for product to be selected. <div ng-init="pr.type=Product"> <div class="form-group"> <label class="radio-inline"> <input type="radio" ng-model="pr.type" id="productType" value="Product"> Product </label> <label class="radio-inline"> <input type="radio" ng-model="pr.type" id="serviceType" value="Service"> Service </label> </div> </div>...

AngularJS - Accessing ng-init variables from run method

angularjs,angularjs-ng-init,ng-init,angularjs-rootscope,angularjs-lifecycle
1) I have variables initialized in ng-init Eg - ng-init="password='Mightybear'"; 2) I want to access it from the .run method. Eg - anguar.module("ngApp", []) .run(function() { //Access password here }); Below scenarios I have tried, and did not work - 1) angular.module("ngApp", []) .run(function($rootScope) { console.log($rootScope.password) //undefined!!! }); 2) angular.module("ngApp",...