I use ui route to change view and use scrollto function. 
<a ui-sref="business({scrollTo: 'business'})"></a>
When I click this link first time, url is 
/index.html#/business/business#business
This is what I want.
When I click this link again, url is changed to
file:///Users/phyuhninwai/Desktop/VIMIC/index.html#/business/business
Here is my angular code
// create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ui.router']);

// configure our routes

scotchApp.config(function($stateProvider) {
$stateProvider

// // route for the home page
// .when('/', {
// templateUrl : 'pages/business.html',
// controller  : 'mainController'
// })

.state('/', {
    url: '/:scrollTo',  
    controller: 'mainController', 
    templateUrl: 'pages/business.html'
  })
.state('business', {
    url: 'business/:scrollTo',  
    controller: 'mainController', 
    templateUrl: 'pages/business.html'
  })

.state('team', {
    url: 'team/:scrollTo',  
    controller: 'teamController', 
    templateUrl: 'pages/team.html'
  })

.state('portfolios', {
    url: 'portfolios/:scrollTo',  
    controller: 'portfoliosController', 
    templateUrl: 'pages/portfolios.html'
  })

.state('investor', {
    url: '/:scrollTo',  
    controller: 'investorController', 
    templateUrl: 'pages/investor.html'
  })

.state('contact', {
    url: '/:scrollTo',  
    controller: 'contactController', 
    templateUrl: 'pages/contact.html'
  });


// route for the about page
// .when('/team', {
// templateUrl : 'pages/team.html',
// controller  : 'teamController'
// })

// // route for the contact page
// .when('/portfolios', {
// templateUrl : 'pages/portfolios.html',
// controller  : 'portfoliosController'
// })

// .when('/investor', {
// templateUrl : 'pages/investor.html',
// controller  : 'investorController'
// })

// .when('/contact', {
// templateUrl : 'pages/contact.html',
// controller  : 'contactController'
// });
});


scotchApp.run(function($rootScope, $location, $anchorScroll, $stateParams, 
$timeout) { 
 $rootScope.$on('$stateChangeSuccess', function(newRoute, oldRoute) {
   $timeout(function() { 
     $location.hash($stateParams.scrollTo);
     $anchorScroll()
   }, 100)
 });
})

// create the controller and inject Angular's $scope
scotchApp.controller('mainController', function($scope) {
// create a message to display in our view
});

scotchApp.controller('teamController', function($scope) {
});

scotchApp.controller('contactController', function($scope) {
});

scotchApp.controller('investorController', function($scope) {
});

scotchApp.controller('portfoliosController', function($scope) {
});
Help me ! 

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to