$location not changing the path in AngularJS
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')
}
});
angularjs
|
show 1 more comment
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')
}
});
angularjs
help me with code please i am begginer
– AbhiRam
15 mins ago
try writing it aswhen('/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 ofotherwise
(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 changeothers_page
toOthersPage
, etc.
– Aleksey Solovey
4 mins ago
|
show 1 more comment
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')
}
});
angularjs
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
angularjs
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 aswhen('/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 ofotherwise
(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 changeothers_page
toOthersPage
, etc.
– Aleksey Solovey
4 mins ago
|
show 1 more comment
help me with code please i am begginer
– AbhiRam
15 mins ago
try writing it aswhen('/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 ofotherwise
(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 changeothers_page
toOthersPage
, 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
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
0
down vote
I suggest this:
- Correct your router: change
'/OthersPage:id?'
to'/OthersPage/:id'
- On the
<button>
element don't use a function to change your path. Use instead anng-href
like this:<a ng-href="/OthersPage/100" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</a>
is there any benefit on usingng-href
than using$location.path
in controller ?
– cjmling
4 mins ago
add a comment |
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:
- Correct your router: change
'/OthersPage:id?'
to'/OthersPage/:id'
- On the
<button>
element don't use a function to change your path. Use instead anng-href
like this:<a ng-href="/OthersPage/100" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</a>
is there any benefit on usingng-href
than using$location.path
in controller ?
– cjmling
4 mins ago
add a comment |
up vote
0
down vote
I suggest this:
- Correct your router: change
'/OthersPage:id?'
to'/OthersPage/:id'
- On the
<button>
element don't use a function to change your path. Use instead anng-href
like this:<a ng-href="/OthersPage/100" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</a>
is there any benefit on usingng-href
than using$location.path
in controller ?
– cjmling
4 mins ago
add a comment |
up vote
0
down vote
up vote
0
down vote
I suggest this:
- Correct your router: change
'/OthersPage:id?'
to'/OthersPage/:id'
- On the
<button>
element don't use a function to change your path. Use instead anng-href
like this:<a ng-href="/OthersPage/100" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</a>
I suggest this:
- Correct your router: change
'/OthersPage:id?'
to'/OthersPage/:id'
- On the
<button>
element don't use a function to change your path. Use instead anng-href
like this:<a ng-href="/OthersPage/100" type="button" class="btn btn-default" style="margin:10px 0px 10px 0px;">Others Page</a>
answered 7 mins ago
Leonardo Minati
136111
136111
is there any benefit on usingng-href
than using$location.path
in controller ?
– cjmling
4 mins ago
add a comment |
is there any benefit on usingng-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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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 changeothers_page
toOthersPage
, etc.– Aleksey Solovey
4 mins ago