$location not changing the path in AngularJS

Multi tool use
Multi tool use











up vote
0
down vote

favorite












I am new for AngularJS and I'm having issue with moving one page to another and i have to pass parameters from main page to details page,I followed below code but its not working and i am getting error ReferenceError: $location is not defined at a.$scope.moveToOthers (showOrders.js:4)



can some one help me please



app.js:



var sampleApp = angular.module('sampleApp', ["ngRoute"]);
sampleApp.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.

when('/AddNewOrder', {
templateUrl: 'templates/add_orders.html',
controller: 'AddOrderController'
}).

when('/ShowOrders', {
templateUrl: 'templates/show_orders.html',
controller: 'ShowOrdersController'
}).

when('/ExpandOrders', {
templateUrl: 'templates/expand_orders.html',
controller: 'ExpandOrderController'
}).

when('/OthersPage:id?', {
templateUrl: 'templates/others_page.html',
controller: 'OthersPageController'
}).

otherwise({
redirectTo: '/AddNewOrder'
});

}]);


show_orders.html



<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script src="controllers/othersPage.js"></script>
<title>AngularJS Routing example</title>
</head>
<body>
<h1>Show orders</h1>
<button ng-click="moveToOthers()" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</button>
</body>
</html>


showOrders.js:



sampleApp.controller('ShowOrdersController', function ($scope, $location) {
$scope.msg = 'This is Show orders screen123';
$scope.moveToOthers = function () {
$location.path('/others_page/100')
}
});









share|improve this question
























  • help me with code please i am begginer
    – AbhiRam
    15 mins ago












  • try writing it as when('/OthersPage/:id', { and use $location.path('/OthersPage/100')
    – Aleksey Solovey
    13 mins ago










  • ReferenceError: $location is not defined at a.$scope.moveToOthers (showOrders.js:4) i am getting this error
    – AbhiRam
    11 mins ago






  • 2




    ah, right, you didn't inject it in your controller: ('ShowOrdersController', function ($scope, $window, $location) {
    – Aleksey Solovey
    10 mins ago






  • 1




    it redirects you there because of otherwise (it can't find a valid URL), there is an error with the URL you are using. from the update I say that you need to change others_page to OthersPage, etc.
    – Aleksey Solovey
    4 mins ago















up vote
0
down vote

favorite












I am new for AngularJS and I'm having issue with moving one page to another and i have to pass parameters from main page to details page,I followed below code but its not working and i am getting error ReferenceError: $location is not defined at a.$scope.moveToOthers (showOrders.js:4)



can some one help me please



app.js:



var sampleApp = angular.module('sampleApp', ["ngRoute"]);
sampleApp.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.

when('/AddNewOrder', {
templateUrl: 'templates/add_orders.html',
controller: 'AddOrderController'
}).

when('/ShowOrders', {
templateUrl: 'templates/show_orders.html',
controller: 'ShowOrdersController'
}).

when('/ExpandOrders', {
templateUrl: 'templates/expand_orders.html',
controller: 'ExpandOrderController'
}).

when('/OthersPage:id?', {
templateUrl: 'templates/others_page.html',
controller: 'OthersPageController'
}).

otherwise({
redirectTo: '/AddNewOrder'
});

}]);


show_orders.html



<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script src="controllers/othersPage.js"></script>
<title>AngularJS Routing example</title>
</head>
<body>
<h1>Show orders</h1>
<button ng-click="moveToOthers()" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</button>
</body>
</html>


showOrders.js:



sampleApp.controller('ShowOrdersController', function ($scope, $location) {
$scope.msg = 'This is Show orders screen123';
$scope.moveToOthers = function () {
$location.path('/others_page/100')
}
});









share|improve this question
























  • help me with code please i am begginer
    – AbhiRam
    15 mins ago












  • try writing it as when('/OthersPage/:id', { and use $location.path('/OthersPage/100')
    – Aleksey Solovey
    13 mins ago










  • ReferenceError: $location is not defined at a.$scope.moveToOthers (showOrders.js:4) i am getting this error
    – AbhiRam
    11 mins ago






  • 2




    ah, right, you didn't inject it in your controller: ('ShowOrdersController', function ($scope, $window, $location) {
    – Aleksey Solovey
    10 mins ago






  • 1




    it redirects you there because of otherwise (it can't find a valid URL), there is an error with the URL you are using. from the update I say that you need to change others_page to OthersPage, etc.
    – Aleksey Solovey
    4 mins ago













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am new for AngularJS and I'm having issue with moving one page to another and i have to pass parameters from main page to details page,I followed below code but its not working and i am getting error ReferenceError: $location is not defined at a.$scope.moveToOthers (showOrders.js:4)



can some one help me please



app.js:



var sampleApp = angular.module('sampleApp', ["ngRoute"]);
sampleApp.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.

when('/AddNewOrder', {
templateUrl: 'templates/add_orders.html',
controller: 'AddOrderController'
}).

when('/ShowOrders', {
templateUrl: 'templates/show_orders.html',
controller: 'ShowOrdersController'
}).

when('/ExpandOrders', {
templateUrl: 'templates/expand_orders.html',
controller: 'ExpandOrderController'
}).

when('/OthersPage:id?', {
templateUrl: 'templates/others_page.html',
controller: 'OthersPageController'
}).

otherwise({
redirectTo: '/AddNewOrder'
});

}]);


show_orders.html



<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script src="controllers/othersPage.js"></script>
<title>AngularJS Routing example</title>
</head>
<body>
<h1>Show orders</h1>
<button ng-click="moveToOthers()" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</button>
</body>
</html>


showOrders.js:



sampleApp.controller('ShowOrdersController', function ($scope, $location) {
$scope.msg = 'This is Show orders screen123';
$scope.moveToOthers = function () {
$location.path('/others_page/100')
}
});









share|improve this question















I am new for AngularJS and I'm having issue with moving one page to another and i have to pass parameters from main page to details page,I followed below code but its not working and i am getting error ReferenceError: $location is not defined at a.$scope.moveToOthers (showOrders.js:4)



can some one help me please



app.js:



var sampleApp = angular.module('sampleApp', ["ngRoute"]);
sampleApp.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.

when('/AddNewOrder', {
templateUrl: 'templates/add_orders.html',
controller: 'AddOrderController'
}).

when('/ShowOrders', {
templateUrl: 'templates/show_orders.html',
controller: 'ShowOrdersController'
}).

when('/ExpandOrders', {
templateUrl: 'templates/expand_orders.html',
controller: 'ExpandOrderController'
}).

when('/OthersPage:id?', {
templateUrl: 'templates/others_page.html',
controller: 'OthersPageController'
}).

otherwise({
redirectTo: '/AddNewOrder'
});

}]);


show_orders.html



<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script src="controllers/othersPage.js"></script>
<title>AngularJS Routing example</title>
</head>
<body>
<h1>Show orders</h1>
<button ng-click="moveToOthers()" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</button>
</body>
</html>


showOrders.js:



sampleApp.controller('ShowOrdersController', function ($scope, $location) {
$scope.msg = 'This is Show orders screen123';
$scope.moveToOthers = function () {
$location.path('/others_page/100')
}
});






angularjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 5 mins ago

























asked 23 mins ago









AbhiRam

41911137




41911137












  • help me with code please i am begginer
    – AbhiRam
    15 mins ago












  • try writing it as when('/OthersPage/:id', { and use $location.path('/OthersPage/100')
    – Aleksey Solovey
    13 mins ago










  • ReferenceError: $location is not defined at a.$scope.moveToOthers (showOrders.js:4) i am getting this error
    – AbhiRam
    11 mins ago






  • 2




    ah, right, you didn't inject it in your controller: ('ShowOrdersController', function ($scope, $window, $location) {
    – Aleksey Solovey
    10 mins ago






  • 1




    it redirects you there because of otherwise (it can't find a valid URL), there is an error with the URL you are using. from the update I say that you need to change others_page to OthersPage, etc.
    – Aleksey Solovey
    4 mins ago


















  • help me with code please i am begginer
    – AbhiRam
    15 mins ago












  • try writing it as when('/OthersPage/:id', { and use $location.path('/OthersPage/100')
    – Aleksey Solovey
    13 mins ago










  • ReferenceError: $location is not defined at a.$scope.moveToOthers (showOrders.js:4) i am getting this error
    – AbhiRam
    11 mins ago






  • 2




    ah, right, you didn't inject it in your controller: ('ShowOrdersController', function ($scope, $window, $location) {
    – Aleksey Solovey
    10 mins ago






  • 1




    it redirects you there because of otherwise (it can't find a valid URL), there is an error with the URL you are using. from the update I say that you need to change others_page to OthersPage, etc.
    – Aleksey Solovey
    4 mins ago
















help me with code please i am begginer
– AbhiRam
15 mins ago






help me with code please i am begginer
– AbhiRam
15 mins ago














try writing it as when('/OthersPage/:id', { and use $location.path('/OthersPage/100')
– Aleksey Solovey
13 mins ago




try writing it as when('/OthersPage/:id', { and use $location.path('/OthersPage/100')
– Aleksey Solovey
13 mins ago












ReferenceError: $location is not defined at a.$scope.moveToOthers (showOrders.js:4) i am getting this error
– AbhiRam
11 mins ago




ReferenceError: $location is not defined at a.$scope.moveToOthers (showOrders.js:4) i am getting this error
– AbhiRam
11 mins ago




2




2




ah, right, you didn't inject it in your controller: ('ShowOrdersController', function ($scope, $window, $location) {
– Aleksey Solovey
10 mins ago




ah, right, you didn't inject it in your controller: ('ShowOrdersController', function ($scope, $window, $location) {
– Aleksey Solovey
10 mins ago




1




1




it redirects you there because of otherwise (it can't find a valid URL), there is an error with the URL you are using. from the update I say that you need to change others_page to OthersPage, etc.
– Aleksey Solovey
4 mins ago




it redirects you there because of otherwise (it can't find a valid URL), there is an error with the URL you are using. from the update I say that you need to change others_page to OthersPage, etc.
– Aleksey Solovey
4 mins ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote













I suggest this:




  1. Correct your router: change '/OthersPage:id?' to '/OthersPage/:id'

  2. On the <button> element don't use a function to change your path. Use instead an ng-href like this: <a ng-href="/OthersPage/100" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</a>





share





















  • is there any benefit on using ng-href than using $location.path in controller ?
    – cjmling
    4 mins ago













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204462%2flocation-not-changing-the-path-in-angularjs%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













I suggest this:




  1. Correct your router: change '/OthersPage:id?' to '/OthersPage/:id'

  2. On the <button> element don't use a function to change your path. Use instead an ng-href like this: <a ng-href="/OthersPage/100" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</a>





share





















  • is there any benefit on using ng-href than using $location.path in controller ?
    – cjmling
    4 mins ago

















up vote
0
down vote













I suggest this:




  1. Correct your router: change '/OthersPage:id?' to '/OthersPage/:id'

  2. On the <button> element don't use a function to change your path. Use instead an ng-href like this: <a ng-href="/OthersPage/100" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</a>





share





















  • is there any benefit on using ng-href than using $location.path in controller ?
    – cjmling
    4 mins ago















up vote
0
down vote










up vote
0
down vote









I suggest this:




  1. Correct your router: change '/OthersPage:id?' to '/OthersPage/:id'

  2. On the <button> element don't use a function to change your path. Use instead an ng-href like this: <a ng-href="/OthersPage/100" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</a>





share












I suggest this:




  1. Correct your router: change '/OthersPage:id?' to '/OthersPage/:id'

  2. On the <button> element don't use a function to change your path. Use instead an ng-href like this: <a ng-href="/OthersPage/100" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</a>






share











share


share










answered 7 mins ago









Leonardo Minati

136111




136111












  • is there any benefit on using ng-href than using $location.path in controller ?
    – cjmling
    4 mins ago




















  • is there any benefit on using ng-href than using $location.path in controller ?
    – cjmling
    4 mins ago


















is there any benefit on using ng-href than using $location.path in controller ?
– cjmling
4 mins ago






is there any benefit on using ng-href than using $location.path in controller ?
– cjmling
4 mins ago




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204462%2flocation-not-changing-the-path-in-angularjs%23new-answer', 'question_page');
}
);

Post as a guest




















































































204CvC5BP9VUNrzZnb jnXFJSBh1dUX 7tgg,5FobjxztyKV,9k0aMS
Rwt,t61To7vC7,C ir,EszPErfEsn4Oco2FUwU1pqVWY0o

Popular posts from this blog

How to pass form data using jquery Ajax to insert data in database?

Guess what letter conforming each word

Run scheduled task as local user group (not BUILTIN)