4

My application assigns variables to the $scope in a controller, like $scope.myVariable = 123; After I run Closure Compiler, that code gets turned into $scope.a = 123; and $scope.b = 123; and so on...

My html templates have things like <p>{{ myVariable }}</p> I need to update the templates to <p>{{ a }}</p> to match the new name of the renamed property myVariable.

I know that I can use the CC /** @expose */ annotation, or I can do something like $scope['myVariable'] = 123 so that CC does not rename that specific property. However, I would like to keep renaming the variable properties.

I have 2 options that I see:

  1. Write a script that uses the _props_map.out from the CC, and write a script that sear-replaces the strings in my HTML.

  2. Write my templates in javascript, so that CC will also process my templates, and then run the template function which spits out html of a template.

What would be the best way to keep renaming my variables and update the template html?

1
  • I'm curious if you managed to solve your problem. I'm using /** @export */ on all controllers' properties I use in the template, which is not ideal. Commented Jan 15, 2016 at 14:44

1 Answer 1

0

I believe the best way is not to rename the variables. I'm not sure what exactly you are trying to achieve but generally speaking, changing variables in templates does not make sense.

You can have <p>{{ a }}</p> in your template from the very start; {{ a }} won't print anything out until a is defined and has some value.

Another option is to create $scope.variables object that will contain your new variables such as

{ a: 123, b: 123 }

and you can use them in your template with <p>{{ variables.a }}</p>.

Would any of these options work for you?

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.