I'm working on integrating Closure into my Angular project, and so far so
good. Building is fine, goog libraries are fine, etc.
However, I am having some issues with property renaming. Specifically:
Controller Code:
/**
* Updates the current list of widgets.
* @export
*/
name.space.widgetController.prototype.getWidgets = function() {
this.scope_.widgets = name.space.WidgetsController.DEFAULT_WIDGETS_LIST_;
};
Partial Code:
<table class=" table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Color</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="widget in widgets">
<td>{{ widget.name }}</td>
<td>{{ widget.color}}</td>
</tr>
</tbody>
</table>
My ng-repeat will never work, because widget is renamed using
ADVANCED_OPTIMIZATIONS. Here is what I am using to compile:
java -jar closure/compiler.jar \
'src/app/**.js' '!**_test.js' 'vendor/closure-library/' \
--angular_pass \
--externs src/externs/**.js \
--js_output_file public/javascripts/application.js \
--generate_exports \
--only_closure_dependencies \
--closure_entry_point=name.space.app \
--compilation_level='ADVANCED_OPTIMIZATIONS' \
--output_wrapper='(function(){%output%})();//#
sourceMappingURL=application.js.map' \
--create_source_map='./public/javascripts/application.js.map'
So I can do two things. One, I can refer to the widgets property as
$scope['widgets']. This doesn't feel right though... I would also like to
point out that my constructors have both @ngInject and @export annotations
- so I don't thing this is the right. I am also telling my compiler (see
above) about the Angular externs.
The second thing I can do is use the @expose property like this:
/** @expose */
this.scope_.widgets = name.space.WidgetsController.DEFAULT_WIDGETS_LIST_;
...but there are a couple of problems with @expose. (1), using expose
generates "JSC_UNSAFE_NAMESPACE" errors, and (2), the Google Closure Docs
<https://developers.google.com/closure/compiler/docs/error-ref> say that
@expose is deprecated, and should be avoided.
I want to use Closure, and the Angular Style guide recommends it, but I am
confused as to how to approach this issue. How should I name/use/expose
$scope properties?
You can also see this question at SO
<http://stackoverflow.com/questions/27389389/cannot-access-scope-properties-after-closure-compiler-property-renaming>
.
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.