Hi. I need to assign $scope.sizes_prices on ng-init and access it in other
function, however I can't see assigned data after init() function complete.
I do the following:
in controller:
@item.controller 'OptionsCtrl', ['$scope', '$http', 'SizesMaterial',
'DrawerBoxFrontOption', ($scope, $http, SizesMaterial, Option) ->
$scope.sizes_prices = []
$scope.init = ->
console.log "NNNN"
SizesMaterial.query
item_id: $scope.item_id
.then (results) ->
$scope.sizes_prices = results
console.log "new $scope"
console.log $scope
console.log "-----"
show me correct (update new $scope with correct $scope.sizes_prices saved)
However when I try to access $scope.sizes_prices in other function I get
empty array (like only $scope.sizes_prices = [] was used):
$scope.final_calculation = ->
return false unless $scope.row
$scope.$watch 'sizes_prices', ->
console.log 'WATCH START'
console.log $scope.sizes_prices
console.log 'WATCH END'
return
return 111
Browser console output:
WATCH START
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:33 []
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:34 WATCH END
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:32 WATCH START
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:33 []
<... many times ...>
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:32 WATCH START
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:33 []
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:34 WATCH END
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:32 WATCH START
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:33 []
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:34 WATCH END
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:32 WATCH START
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:33 []
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:34 WATCH END
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:32 WATCH START
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:33 []
options-15212d535a6b075ac8b3ee3c44beedc9.js?body=1:34 WATCH END
angular-ebd9269b31100c3cada233d21d55462c.js?body=1:11656 Error:
[$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: <...>
if I remove "$scope.sizes_prices = []" I get undefined on
$scope.sizes_prices.
in resources.coffee:
@item.factory 'SizesMaterial', ['railsResourceFactory',
(railsResourceFactory) ->
railsResourceFactory
url: '/sizes_materials'
name: 'sizes_material'
]
in view:
%div{ng_controller: 'OptionsCtrl', 'ng-init' => "init()", ...
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.