bug: controllerAs syntax in ion-view
Type: bug
Platform: all
There is still an issue with the controllerAs syntax and ion-view (beta 14)
this issue #2499 is still happening here is a repro codepen: http://codepen.io/thaiat/pen/zxPMbL
if you change line 16 to the commented part, it's working The issue is related to views in state
:+1:
:+1:
temporary solution: controller: 'pageController as ctrl'
still using the temporary solution... ng-controller: 'pageController as ctrl'
Would be great if the controllerAs syntax was supported. I'm just trying to change my code to adhere more closely to john papa's fabulous angular style guide and I just spent an hour trying to figure out what I was doing wrong by using controllerAs: 'vm' only to find out that this is an ionic problem.
@elebetsamer Same with me! I spent an hour trying to make controllerAs syntax with Ionic. Even I am following john papa's style guide! But what about when using es6? His style guide has minor issues with respect to es6?
@SiddharthaRRamesh I'm not crossing that bridge yet. Think I'm going to wait for angular 2 and ionic 2 before worrying about it.
@elebetsamer, @SiddharthaRRamesh, Yes, I was following john papa's fabulous angular style guide, too. Only to find out ionic currently works with controller: 'XxxController as vm'. I think we might as well follow this style now
@SiddharthaRRamesh I use ES6 with ionic too. To circumvent this issue, I injected $scope into the controller class and assigned this to $scope.ctrl. Thus I don't have to change my template markup and it just looks as if the controllerAs syntax worked.This trick works well in my app.
My code looks like this:
class LoginController {
constructor($scope) {
$scope.ctrl = this;
}
// some method definitions...
}
LoginController.$inject = ['$scope'];
Just sent PR #3651 to fix this issue. Hopefully it will be merged soon :)
@urish you are everywhere !!!!! ;)
Same with you @thaiat :)
p.s. here is the repro codepen with the fixed ionic version: http://codepen.io/anon/pen/QbbQPo
+1 Would love for this to be resolved!
+1 for this being resolved! Thanks to @urish hopefully this will be resolved soon :+1:
+1 would be great to make this work
+1 looking forward to having this added as well
+1 please make it happend
+1
+1
Very annoying bug, please fix this!
+1