Prevent access of members by controller in views?

Hi there,

I’m working with Ionic 2 and I like it very much. Nice to have this framework :slight_smile:

There are ways to declare private and public (and so on …) members in a class for … reasons, that we have, short and sweet. Is there a way to declare members in my controller class that must not be used in any way by the view?

As I didn’t expected I can access private members of my controller inside of the view. I would have expected that only the public members would be accessible. But for … reasons … I want to explicitly prohibit access to members in the controller when I’m trying to access them from the view by.

I want to have these access modifiers for access by view elements, too. Like at clean code type strictness, I would expect to have these modifiers for view elements, just for clean coding purpose and for preventing misapplication of members of controller classes …

Is there a way to accomplish anything like that?

Thanks and have a nice day!

Did you try this experiment in a production release (--prod)? It should fail unless ionic-app-scripts is transpiling to ES5 early again. In that case, no, there’s nothing more that you can do, because once we get to ES5, the entire notion of access control is gone. JavaScript is a horrendous language, and nary a day goes by that I lament that we are fated to work with it.

You’re supposed to be able to simulate private properties with WeakMap. I haven’t tested this, and I don’t know how well it works across platform, but here’s the link if you want to give it a try. If you do implement it, I’d be interested to know how well it works.

Thanks for your replies.