- Include a reference to ng-route file (angular-route.min.js)
- Add ng-route as module dependency (In app.js file)
- Add a ng-view directive
- We need to create client side routes in our app by configuring them in the route service
- Services in angular are configured using underline provider
- We need to add new routes using the app provider
Place where we specify the route
App.config file
var app = angular.module('ShoppingCart', ['angularUtils.directives.dirPagination', 'ngSanitize', 'ui.select', 'ngRoute']);
app.config(function ($provide, $routeProvider, $locationProvider) {
$routeProvider.when("/", {
controller: "homeCtrl",
controllerAs: "vm",
templateUrl: "/Views/homeView.html"
});
$routeProvider.when("/home", {
controller: "homeCtrl",
controllerAs: "vm",
templateUrl: "/Views/homeView.html"
});
$routeProvider.when("/Registration", {
controller: "registrationCtrl",
controllerAs: "vm",
templateUrl: "/Views/registrationView.html"
});
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
$routeProvider.otherwise({ redirectTo: "/" });
})
CSHTML
<link href="~/css/release/registration.css" rel="stylesheet" />
<script src="@Url.Content("~/js/angular/app.js")"></script>
<script src="@Url.Content("~/js/angular/RegistrationCtrl.js")"></script>
<div ng-app="ProducerCentral">
<div ng-view></div>
</div>
No comments:
Post a Comment