davej / angular-classy

Cleaner class-based controllers with Angular 1
http://davej.github.io/angular-classy/
813 stars 27 forks source link

angular ui router: state resolve not working with angular classy #51

Closed janbee closed 6 years ago

janbee commented 7 years ago

Hi, Im using 1.2.4 classy, I have an issue using ui router resolve

  `$stateProvider.state({
        name: 'public',
        url: '',
        views:{
            'main' : {template: '<public data="$resolve.$test""/>'}
        },
        resolve: {
            $test: function($stateParams, $http) {
                return $http.post('/me',{});
            }
        }
    })`

using the normal this is working with $onInit

`app.component('public', {
    template: require('./public.html'),
    bindings: {data: '='},
    controller:  function(){
        var self = this;
        this.$onInit = function(){
            console.log("-------------------------",self.data);
        }
    }
})`

in angular classy init:function its not

any advice?

davej commented 7 years ago

I haven't tested with ui-router resolvers but I can do a bit of debugging if you're able to provide a plunkr of what you're trying to do.

janbee commented 7 years ago

I made it work, seems like its working like this

publicMod.component('public', { template: require('./public.html'), bindings: { $me:'<' }, controller: publicMod.classy.controller({ name :'PublicCtrl', inject:['$scope','$state','$element'], methods: { $onInit:function(){ let self =this; console.log("2cheasdasdadasck data",self.$me); } }

 })

});

the "self.$me" var is the promise from ui router resolve. But is it safe to use the $onInit?, just like using it on the old component way like below

|.component('myPane',{controller:function(){this.$onInit =function(){console.log(this);};},templateUrl:'my-pane.html'});|

Cheers, Janbee On 11/04/2017 4:03 PM, Dave Jeffery wrote:

I haven't tested with ui-router resolvers but I can do a bit of debugging if you're able to provide a plunkr https://plnkr.co/ of what you're trying to do.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/davej/angular-classy/issues/51#issuecomment-293182200, or mute the thread https://github.com/notifications/unsubscribe-auth/AB-uzLauJAGBYXqsvcyUVKCMDclA4b_xks5ruzPXgaJpZM4M5mix.

davej commented 7 years ago

It's difficult for me to debug because I'm not familiar with ui-router. If you put it in a plunkr then I should be able to answer you better.