Angular -ui-router nested named views using typescript

Hi, I am new to typescript with little experience with angular. I tried to get a pretty normal angular -ui-router setup that works with typescript, but I just can't figure out what I am missing. I have two nested named views that don't seem to load at all.

application /app.ts

module myModule{
class MyConfig {
    constructor( private $stateProvider:ng.ui.IStateProvider,
                 private $urlRouterProvider:angular.ui.IUrlRouterProvider ) {
        this.init();
    }

    private init():void {
        this.$stateProvider.state( 'home',
            {
                abstract:true,
                template: '<main></main>',
                url: '/'
            }).state('home.main',
            {
                views: {
                    'lhp@home': { template: '<lhp></lhp>' },
                    'rhs@home': { template: '<rhs></rhs>' }
                },
                url: '/main',
            });

        this.$urlRouterProvider.otherwise('/main');
    }
}

let myApp = angular.module( 'myModule', ['ui.router'] );
myApp.config(['$stateProvider', '$urlRouterProvider', ($stateProvider, $urlRouterProvider) => {
    return new MyConfig($stateProvider, $urlRouterProvider);
}]);

}

The main directive is a simple div that is a container for the two named views

main.html / main.controller.ts

module app.Controllers {
    export class MainController {
        constructor( private $log:ng.ILogService ) {
            this.Init();
        }

        private Init() {
            this.$log.info('Main Controller');
        }

    }

    angular.module('myModule').controller( 'mainController', ['$log', MainController] );
}

applications / components / main.html

<div>
    <div id="wrap">
        <div id="left_col" ui-view="lhp"></div>
        <div id="right_col" ui-view="rhs"></div>
    </div>
</div>

applications / components / main.directive.ts

module app.Directives {
    'use strict';
    export class MainDirective implements ng.IDirective {
        public templateUrl:string = 'components/main.html';
        public restrict:string = 'E';
        public controller:string = 'mainController';
        public scope = {};

        constructor(private $log:ng.ILogService) {
            this.$log.info('main directive');
        }

        public static Factory() {
            return (log:ng.ILogService) => {
                return new MainDirective(log);
            };
        }
    }

    angular.module('myModule').directive('main', ['$log', app.Directives.MainDirective.Factory()]);
}

applications / components / lhp.controller.ts

module app.Controllers {
    export class LhpController {
        constructor( private $log:ng.ILogService ) {
            this.Init();
        }

        private Init() {
            this.$log.info('LHP Controller');
        }
    }

    angular.module('myModule').controller( 'lhpController', ['$log', LhpController] );
}

applications / components / lhp.html

<div style="width: inherit">
    THIS IS A TEST
</div>

applications / components / lhp.directive.ts

module app.Directives {
    'use strict';
    export class LhpDirective implements  ng.IDirective {
        public templateUrl:string = 'components/lhp.html';
        public restrict:string = 'E';
        public controller:string = 'lhpController';
        public controllerAs:string = 'lctrl';
        public scope = {};

        constructor(private $log:ng.ILogService) {
            this.$log.info('lhp directive');
        }

        public static Factory() {
            return (log:ng.ILogService) => {
                return new LhpDirective(log);
            };
        }
    }

    angular.module('myModule').directive('lhp', ['$log', app.Directives.LhpDirective.Factory()]);
}

rhs , lhp. , rhs lhp , . . , . , html, . typescript ? - typescript ? , . , , : stateprovider ui-router Typescript?, , typescript . - Typescript?

.

+4
1

. . url :

private init():void {
    this.$stateProvider.state( 'home',
        {
            abstract:true,
            template: '<main></main>'
        }).state('home.main',
        {
            views: {
                'lhp@home': { template: '<lhp></lhp>' },
                'rhs@home': { template: '<rhs></rhs>' }
            },
            url: '/main',
        });

    this.$urlRouterProvider.otherwise('/main');
}
0

Source: https://habr.com/ru/post/1629820/


All Articles