How do I shorten to write {{id}} instead of {{object.id}} in angularjs? (when 'object' is json) -
this maybe basic question, couldn't google ages.
say have $scope
$scope.object = {id:1, name:"stackoverflow"};
and in html, want call simply
{{id}}
instead of
{{object.id}}
is there simple way achieve this? (without loop map json attributes $scope variables etc)
maybe simple like... (i know won't work)
<div ng-scope="object"> {{id}} </div>
==== update ===
guess there's no default (natural or easy) way of achieving without manipulating $scope. (i.e. adding more watches (= overheads) etc)
well... after more research, think maybe bad idea in angularjs. see video. https://egghead.io/lessons/angularjs-the-dot
i wanted use existing code laravel (blade templating engine). guess have write '.'(dots) prevent unexpected behaviors now. have 100s of them, feels repetitive.
this simple task in backend frameworks.
i vote relevant answers! :d
thanks!
can simple directive that:
mymodule.directive("ngshort", function(){ return function(scope, elem, attrs){ scope.$watch(attrs.ngshort,function(){ angular.extend(scope, scope.$eval(attrs.ngshort)) }, true) } })
<div ng-short="object"> {{id}} </div>
Comments
Post a Comment