×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Nilesh Yadav
Added: Jun 12, 2017 6:50 AM
Views: 2
Tags: no tags
  1. var app = angular.module('app',['ui.router']);
  2.  
  3. app.config(['$stateProvider','$urlRouterProvide',function($stateProvider,$urlRouterProvide){
  4.        
  5.         $stateProvider
  6.         .state('firstMessage',{
  7.           url:'/first-msg',
  8.           // template:'<strong>hi this is first message</strong>'
  9.           templateUrl:'msg1.html',
  10.           controller:'msg1'
  11.         })
  12.  
  13.         .state('secondMessage',{
  14.           url:'/first-msg',
  15.           templateUrl:'msg2.html',
  16.           controller:'msg2'
  17.         })
  18.  
  19.         .state('root',{
  20.           url:'/',
  21.           template:'<strong>you are at root</strong>',
  22.         })
  23.  
  24.         .state('noroute',{
  25.           url:'*path',
  26.           template:'<strong>no route available.. 404</strong>',
  27.         })
  28.  
  29.         // $urlRouterProvide.otherwise('/') alternatve to noroute
  30.  
  31. }])
  32.  
  33. app.controller('msg',['$scope',function($scope) {
  34.        
  35. }])
  36.  
  37. app.controller('msg2',['$scope',function($scope) {
  38.        
  39. }])
  40.  
  41.  
  42. <!-- <a href="#/">root</a> -->
  43. alternative of above anchor tag
  44. <a ui-sref='firstMessage()'>first messgae</a>
  45.  
  46.  
  47.  
  48. <div ui-view>
  49. </div>