angular / router

The Angular 1 Component Router
MIT License
665 stars 135 forks source link

Can we use the angular 1.5 component() construct with the angular-new-router? #386

Closed jusefb closed 8 years ago

jusefb commented 8 years ago

I am starting to look at the new "component" feature introduced in Angular 1.5. Can this be used with the new angular router? It seems to be a natural thing to use this feature for easy migration to angular 2 at a later stage.

amritk commented 8 years ago

I just tried it and it doesn't look like it works, but you're right its the natural thing to use.

iksose commented 8 years ago

have you looked @ the examples here https://github.com/brandonroberts/angularjs-component-router

amritk commented 8 years ago

@iksose In those examples, he's making new modules for each component. Here are my routes:

    const AppComponent = {
        controller: function ($router: any) {

            console.log('app controller');
            $router.config([
                {
                    path: '/angular',
                    component: 'feedz'
                }
            ])
        },
        template: '<ng-outlet></ng-outlet>'
    }

I'm not sure what I'm missing here but this doesn't work (no errors, just a blank page with no components loading):

    const FeedzComponent = {
        controller: function ($router: any) {
            console.log('feedz loaded');
        },
        template: 'wah wah whee wah'
    }

    angular.module('Community').component('feedz', FeedzComponent);

Yet this works:

    const FeedzComponent = {
        controller: function ($router: any) {
            console.log('feedz loaded');
        },
        template: 'wah wah whee wah'
    }

    angular.module('Community').directive('feedz', function (){
        return FeedzComponent;
    });

The only difference is the working one is using the old directive, while the non-working one is using the new component syntax.

ArniDzhan commented 8 years ago

here is an example of a new export of router from angular 2.0 project, it works with 1.5 components and fixed many other issues. Which this current project is not being updated. So do search https://github.com/angular/angular/ for updated related to router.

http://plnkr.co/edit/N3YP3dKMuljpZ6mWsVBT?p=preview

ArniDzhan commented 8 years ago

actually following this demo project may be useful https://github.com/petebacondarwin/ng1-component-router-demo

amritk commented 8 years ago

definitely works now, thanks @ArniDzhan

jusefb commented 8 years ago

Thanks

ArniDzhan commented 8 years ago

welcome :)