Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use RouteProvider in AngularJS

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 218
    Comment on it

    With the help of Routing method we can divide our application in logical views and bind different view to controllers". In below example we have use first config() method to define $route Provider configuration. Also in the same file we defined two controllers AddOrderController and ShowOrdersController.

    //Define an angular module for our app
    var sampleApp = angular.module('sampleApp', []);
     
    //Define Routing for app
    //Uri /AddNewOrder -> template add_order.html and Controller AddOrderController
    //Uri /ShowOrders -> template show_orders.html and Controller AddOrderController
    sampleApp.config(['$routeProvider',
      function($routeProvider) {
              $routeProvider.
              when('/AddNewOrder', {
              templateUrl: 'templates/add_order.html',
                    controller: 'AddOrderController'
              })
                    when('/ShowOrders', {
              templateUrl: 'templates/show_orders.html',
               controller: 'ShowOrdersController'
            })
            otherwise({
            redirectTo: '/AddNewOrder'
             });
    }]);
    
    sampleApp.controller('AddOrderController', function($scope) {
    
    $scope.message = 'This is Add new order screen';
    
    });
    sampleApp.controller('ShowOrdersController', function($scope) {
    
    $scope.message = 'This is Show orders screen';
     });
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: