2

I have a very weird issue.

I have an object under the $scope

I using an angular.foreach loop but there is a problem.

when I'm trying to set a value depending on langKey(where langKey is 'en' or 'el') all the values are being updated by ingoring the langKey.

$scope.finalObject[langKey]['servicesElements'][itemKey]['name']  = something;

the problem still exists when I simply use the console in order to change the values from there.

I'm setting the value 'myCustomText' to the el version of the object

$scope.finalObject.el['servicesElements'][itemKey]['name'] = 'myCustomText'

BUT if i run this one

$scope.finalObject.en['servicesElements'][itemKey]['name']

it returns 'myCustomText' with no reason because what I changed was the el version not the en.

Is this normal? I'm totally stuck

Thank you in advance

2
  • 1
    Could you create a Plunker script or something? Commented Sep 5, 2013 at 14:06
  • I'd recommend you check out the angular-translate module over at ngmodules.org/modules/angular-translate. Also you'll need to post more code for your specific problem, it sounds like there's an issue with your loop somewhere. Commented Sep 5, 2013 at 14:11

1 Answer 1

1

Well guys,

The problem was that I had declared the two different objects with the same source.

$scope.finalObject.el.servicesElements = something;

and

$scope.finalObject.en.servicesElements = something 

I didn't have seen that before, but the browser was behaving like I have typed

$scope.finalObject.en.servicesElements = $scope.finalObject.el.servicesElements = something

and in every change of the one the other was following.

(in php is called pointer)

The solution was to use the angular's copy function

http://docs.angularjs.org/api/angular.copy

So I simply used this SO answer Reset a model with angular.js did this

$scope.tmpVar = something;
$scope.finalObject.en.servicesElements = angular.copy($scope.tmpVar);
$scope.finalObject.el.servicesElements = angular.copy($scope.tmpVar);
Sign up to request clarification or add additional context in comments.

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.