jeudi 5 novembre 2015

angularjs passing value for object

Vote count: 0

$scope.passingValueForObject = function(which, value) {
  $scope.object.which.push(value);
}

I want use "which" to push that want index. how to do that?

asked 9 mins ago

3 Answers

Vote count: 0

$scope.object.which = []
$scope.passingValueForObject = function(which, value) {
  $scope.object.which.push(value);
}

answered 1 min ago

Vote count: 0

Use the following syntax where "which" is the key of the object:

$scope.object[which].push(value);

answered 1 min ago

Vote count: 0

Well, if it's only one object, you can just do this:

var ctrl = this;

this.passingValueForObject = function(obj, value) {
  ctrl.obj.attr = value;
}

Now, if we're talking about an array of objects, you can do this:

var ctrl = this;

this.objs = [ obj1{}, obj2{} ];

this.passingValueForObject = function(objs, index, value) {
  ctrl.objs[index].attr = value;
}

answered 1 min ago

This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at http://ift.tt/jcXqJW.



angularjs passing value for object

Aucun commentaire:

Enregistrer un commentaire