javascript - refactor angular-route to angular-ui-router -


i've created single page application using ngroute so:

index.html (ngroute)

var smalltalkzmodel = angular.module('smalltalkzmodel', ['ngroute']); smalltalkzmodel.config(function($routeprovider) {      $routeprovider     .when('/', {       templateurl : 'components/login/loginview.html',       controller  : 'logincontroller'     })      .when('/chat', {       templateurl : 'components/chat/chatview.html',       controller  : 'chatcontroller'     });   }).run(function ($rootscope) {      // app loading, set isapploading true , start timer     console.log($rootscope);     $rootscope.isapploading = true;    });; 

small-talkz.model.js (ngroute)

 <div ng-app="smalltalkzmodel" >     <div ng-view>     </div>   </div> 

then heard better use ui.router because 3rd party have more capabilities , can ngroute , more , supported in future version of angular js...

so, tried refactore code code below. not work...

can tell me why? did not use ng-surf because don't have links html. them localhost:3000/somepage , not navigation...

index.html (ui.router)

<div ng-app="smalltalkzmodel" class="loader">     <div ui-view>     </div> </div> 

small-talkz.model.js (ui.router)

var smalltalkzmodel = angular.module('smalltalkzmodel', ['ui.router']); smalltalkzmodel.config(function($stateprovider, $urlrouterprovider) {    $stateprovider   .state('login', {     url: '/',     templateurl : 'components/login/loginview.html',     controller  : 'logincontroller'   })    .state('chat', {     url: '/chat',     templateurl : 'components/chat/chatview.html',     controller  : 'chatcontroller'   }); });; 

expecting have included library ui-router.js in project. code looks fine. 1 thing think might me causing issue define route when none of states defined matches state of application. use otherwise option below:

$urlrouterprovider.otherwise('/'); 

code should like:

smalltalkzmodel.config(function($stateprovider, $urlrouterprovider) {    $stateprovider   .state('login', {     url: '/',     templateurl : 'components/login/loginview.html',     controller  : 'logincontroller'   })    .state('chat', {     url: '/chat',     templateurl : 'components/chat/chatview.html',     controller  : 'chatcontroller'   })   $urlrouterprovider.otherwise('/'); 

});


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -