简体   繁体   中英

Angular - Dynamically Build A Scope

Is it possible to achieve something along the lines of this

var count = 1;

var blah = $scope.someThing_ + count;

So that blah would be equal to

$scope.someThing_1

I feel like this should work, but it does not seem to be working!

Thanks :)

I'm not sure that it is good idea to store data with dynamically created names of variables, but if you really need in it you could work with properties in js also in this way:

$scope["property_name"]

It means that you could save some value with counter like that:

$scope["someThing_" + count] = "value"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM