Reputation: 4734
suppose I am binding to a model using a long expression such as
<ul class="container" ui-sortable ng-model="cssRules.categories['sd-text-highlight- color']" ng-class="{selected: cssRules.categories['sd-text-highlight-color'] == selectedCategory}" ng-click="selectCategory(cssRules.categories['sd-text-highlight-color'])">
is there a way to not repeat cssRules.categories['sd-text-highlight-color'],
and just bind to the currently referenced model using some keyword or assigned variable name?
Upvotes: 0
Views: 484
Reputation: 13918
Why don't you expose it trough the controller
like:
$scope.cssCategory = cssRules.categories['sd-text-highlight-color']
[UPDATE]
With regards to ng-init
alternative (from Angular documentation):
The only appropriate use of
ngInit
is for aliasing special properties ofngRepeat
, as seen in the demo below. Besides this case, you should use controllers rather thanngInit
to initialise values on a scope.
This might be a reason that it doesn't work well with ui-sortable
so I guess this approach should be avoided.
Upvotes: 2
Reputation: 14440
Try it with ng-init :
<ul
class="container"
ui-sortable
ng-init="mymodel = cssRules.categories['sd-text-highlight-color']"
ng-model=""
ng-class="{selected: mymodel == selectedCategory}"
ng-click="selectCategory(mymodel )"
>
Hope this helps
Upvotes: 2