javascript - Performance of $rootScope.$new vs. $scope.$new -
my current controllers $scope
kind of thick with: $watch
, event handlers.
on 1 point need create new scope modal, not have own controller, because quite simple. still needs property of current $scope
. wondering of following solutions better, , why?
a)
var modalscope = $rootscope.$new(); modalscope.neededvalue = $scope.neededvalue;
b)
var modalscope = $scope.$new(); // modalscope.neededvalue there
should worried created modalscope
watch expressions , events? other aspects should aware of?
option a) copies value once , doesn't keep in sync $scope
, may cause confusing bugs. if modal has deep scope hierarchy there cases option a) might give slight performance advantage (calling $broadcast
on $scope
means needs cover smaller scope tree), in i'd option b) way go.
your $watch
es won't benefit location of scope unless you're $digest
ing particular scope.
edit: see modal light, in case, go option b), performance advantage a) negligible.
Comments
Post a Comment