javascript - Set context scope in Angular -
i have variables bound this
in controller, , in route designation use controlleras: 'game'
. allows me include them in html {{game.var}}
. sometimes, bind objects want display, forces me write repeatedly {{game.object.a}}
, {{game.object.b}}
, {{game.object.c}}
.
in previous project using meteor, set data context with
keyword.
{{#with object}} {{a}} {{b}} {{/with}}
but don't see similar feature in angular. closest i've been able make work adding attribute ng-repeat="object in [game.object]"
. works, isn't semantic. causes me quick flash of second element when game.object
changes, new 1 loads before first 1 erased.
is there better solution problem?
angular intentionally uses context scope avoid confusion between parent , child scopes. if you're not using child scopes, can skip controller syntax entirely , bind $scope
in model, turns game.a
, game.b
a
, b
in view.
if using child scopes, can still skip controlleras, becomes confusing controller given model in view belongs to. there's no with
or using
syntax, need declare bound scope game.a
, childgame.a
everywhere refer these models, might overly verbose @ least clear.
see this post, well.
regarding flash issue, avoid using ng-repeat semantic purposes. it's primary use case display array of structured data.
Comments
Post a Comment