Dinesh Rawat Dinesh Rawat - 28 days ago 5
AngularJS Question

How to create more than one index pages in angular js?

I am new in Angular.js. I have a simple HTML page (angular layout). I want to ask:-

1: Is it possible to have more than one index pages for the project? If yes, then how?

2: Is it possible to make section dynamic, based on the state url?

(Angular-1)

Thank you all in advance!

Answer

Yes you can set partial views and independent controller in angular js. You can set that in your project config. This is a sample implementation.

(function () {
    'use strict';

    angular.module('YourApp', [
        'ngRoute'
    ])

    .config(['$routeProvider', function ($routeProvider) {
        $routeProvider.when('/login', {
            templateUrl: 'login.html',
            controllerAs: 'loginCtrl',
            controller: 'loginController'
        });
        $routeProvider.when('/dashboard', {
            templateUrl: 'dashboard.html',
            controllerAs: 'dashboardCtrl',
            controller: 'dashboardController'
        });
        $routeProvider.otherwise({
            redirectTo: '/login'
        });
    }]);
})();

Here the login.html and dashboard.html are your partial view file and loginController, dashboardController are your controller for respective views.

Comments