Closed fabulouslord closed 9 years ago
I'm sorry I don't really understand your question. Methods prefixed with _
currently won't be put in the scope.
If you're worried about $scope
pollution then you should look into the 'contoller as' syntax, it is compatible with Classy and will give you what I think you're looking for.
What I mean is that I don't want non prefixed methods to be put into the scope as well, as they pollute the scope and I would like to put them into an object and expose the object instead, while still being able to utilize the underscore to denote private methods and non prefixed methods to denote public methods. What is it that "controller as" syntax? , couldn't find any reference.
Cheers.
You can do this globally with:
myApp.classy.options.controller = {
addToScope: false
};
or on a per-controller basis
myApp.classy.controller({
name: 'TodoCtrl',
inject: ['$scope', 'filterFilter'],
__options: {
addToScope: false
}
// ...
});
More info on controller-as here: http://toddmotto.com/digging-into-angulars-controller-as-syntax/ Also check out the FAQs here: http://davej.github.io/angular-classy/
By the way if you only want to apply this behaviour to methods (and not the data
object) then you could do this:
myApp.classy.options.controller = {
bindMethods: {
addToScope: false
}
};
Does that answer all your questions?
Yes it does Dave! Thanks for the quick feedback!
Is this possible? I would like to prefix with _ the methods utilized by other public methods but don't expose this public ones as they get put directly into the scope, which is widely recognized as a bad practice.
E.g.
So instead of calling it like
I can call it like
but currently the method would be still be put into the scope directly and I could call it either way, which I do not want to.
I hope I make sense, and look forward to a reply.