0
var myApp = angular.module('LoginApp',[]);

myApp.controller('dynamic', ['$scope', function($scope) {
   $scope.a_1= "Admin";

   $scope.auction_no = 1;

   $scope.item = [{ A:"a" , B:1 }];
}]);

I have to give model name in HTML in {{ x }} , x should be {{item.A}}_{{auction_no}} like this . and finally it should give output Admin

4
  • Can you please add an example as exactly what do you want to extract? Commented Dec 4, 2015 at 19:43
  • Your question is not very clear can you please explain a little more. Commented Dec 4, 2015 at 19:44
  • Create a service that acts as a go-between for your controllers. Inject this service into both of them, and modify as necessary. One solution would be to use $q to create a promise that you never resolve but watch for updates, and use that as the cue to update your models. Commented Dec 4, 2015 at 19:44
  • Sorry.... I had edited the ques. Commented Dec 5, 2015 at 16:11

2 Answers 2

1

You can use the bracket accessor $scope[$scope.item[0].A + "_" + $scope.auction_no]

Sign up to request clarification or add additional context in comments.

Comments

0

If you are able to make your first variable an object:

$scope.auctions = {
  a_1: 'Admin'
};

$scope.auction_no = 1;
$scope.item = [{ A:"a" , B:1 }];

var x = $scope.auctions[$scope.item[0]['A'] + '_' + $scope.auction_no];

The variable x should hold the value Admin at this point.

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.