0

I have an object which contains 2 properties and array of 4 objects($scope.details) I am trying to append a new object as a property to $scope.details.

enter image description here

this is the way i am trying:

         var routeId;
         var obj=new Object();
         obj.routeId = $routeParams.id;
         $scope.details = obj;

however not getting results. any suggestion on this?

1
  • 2
    Can you please replace the image with complete code? It is much easier for people to try and reconstruct your issue copying and pasting code, rather than reading it from an image. See How to Ask and minimal reproducible example. If possible, create live demo that'll show the problem. Commented Apr 7, 2016 at 13:26

4 Answers 4

0

From what I understood, you want to append $routeParams.id to $scope.details.
So $scope.details = yourNewObject will NOT work, as it will just replace it and not append it.

why var obj=new Object() when you can just var obj={}?

Solution:

$scope.details['routeId']=$routeParams.id

OR

$scope.details.routeId=$routeParams.id
Sign up to request clarification or add additional context in comments.

Comments

0

Try this...

     var routeId = "some value";
     var obj=new Object();
     obj["routeId"]= $routeParams.id;
     $scope.details = obj;

Or you could simply do this..

var obj = {};
ob.propertyName = $routeParams.id;
$scope.details = obj;

We would like to see some code, before we could give more app solutions.

Comments

0

It's difficult to say what is happening here without some more code.

However, it's likely that you are updating your $scope object outside of an angular "digest cycle", so angular is not aware of the change. http://www.sitepoint.com/understanding-angulars-apply-digest/

To force angular to run a digest cycle, you can call $scope.$apply()

var obj = {
    routeId: $routeParams.id
};
$scope.details = obj;
$scope.$apply();

Comments

0

You're thinking about this way too hard, nothing to do with Angular.

If you want $scope.details to contain something called route just add it.

$scope.details.route = {"routeId": $routeParams.id, "YourOtherAwesomeRouteStuff": "OtherCoolValues"}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.