javascript - Isolate scope variable inside ng-repeat -
i'm building end ios application , it's made angularjs, admins can manage data website please. data consists of multiple , diverse elements. 1 of elements are, let's say, boxes. each box contains pointer present, , each present has name. it's box -> present.name, if know mean.
the problem i'm dealing need show boxes in list (don't worry in code example ahead, simplified it), , content of each list item should name of present belongs each box. data has obtained parse.com, need call function given box retrieves present , allows name.
this have right now:
<div ng-repeat="box in boxes"> <span ng-init="getpresentfromobject(box)"> {{relatedpresent.get("name")}} </span> </div>
the problem obvious. i'm using $scope.relatedpresent
hold value of each present (one each box), it's updating value each iteration , @ end end list of elements, of them presenting same name, 1 of last present, last update $scope.relatedpresent
variable.
i'd value isolated changes, each box has own present , name doesn't vary in other iterations. tried angularjs directives couldn't make them work, i'm stuck. must pretty simple accomplish this, cannot find way.
update
the function call ng-init
makes async call, i'm not sure if can return value object in ng-init
inside html code.
$scope.getpresentfromobject = function (object) { getpresentobjectfromobject(object) .then(function (thepresent) { $scope.relatedpresent = thepresent; // if return here value goes }, function (error) { // error stuff }); // if return here lost value because it's async }
i hope flow clearer now.
have tried assigning value ng-init?
<div ng-repeat="box in boxes"> <span ng-init="present = getpresentfromobject(box)"> {{present.get("name")}} </span> </div>
see ng-init docs further info
Comments
Post a Comment