Ionic creating childscope in


#1

Hey there.
Refering this issue on git: https://github.com/driftyco/ionic/issues/977

I am having trouble understanding why there should be another childscope created by

This creates problems such as I cannot access variables declared and filled via ng-model from my controller functions.

to clarify. this wont work:

<ion-content>
<input ng-model="foo">
</ion-content>

$scope.myfunc = function(){
someService.moo($scope.foo);
}

someService.moo will be called with a null value since the controller can’t find the foo variable which is in the childscope created by ionic. doesn’t this defeat the whole angular 2 way data binding idea?


#2

You’re using primitives - so 2 way binding is going to fail.

You should be using objects “dot notation”.

$scope.data = { "foo" : "something-goes-here" }


#3

thanks for clearing this up for me. I did create the variables i wanted to use in my views in my controller first most of the time which is why I never came across this error until now. Also if I didn’t do it then I probably never had a situation with a childScope which would have made me aware.

So I guess I better stick to my (personal?) practice of having an init function in my controller which is called when loaded and that instantiates all variables I later use in my view. This also helps me keep a good overview of all the variables I have.