[英]Angular.js change location ng-click
I've read some other posts on the same topic but cannot get my own to work. 我已经阅读了关于同一主题的其他一些帖子,但无法让我自己去工作。 Basically, I want the location of my app to change on a ng-click event. 基本上,我希望我的应用程序的位置在ng-click事件上更改。 So I have html code that looks like this: 所以我有html代码,如下所示:
<button class="button icon-left ion-plus-round button-block button-calm" ng-click="send({{foods.cal}})">
Add Calories
</button>
And a controller that looks like this: 一个看起来像这样的控制器:
.controller('foodDetailCtrl', function($scope, $stateParams, $location, foods) {
$scope.foods = foods.get($stateParams.foodsId);
$scope.send = function(i) {
// do something with 'i'
$location.path('/calc');
}
})
But when I click on my html button the location gets refreshed to a home tab as if it cannot find '/calc'. 但是当我点击我的html按钮时,该位置会刷新到主页选项卡,好像它找不到'/ calc'。 I've tried calc preceeded by parents folders and followed with file extension but cannot get this to work. 我已经尝试过calc之前的父文件夹,然后是文件扩展名,但无法使其工作。 Any help massively appreciated. 任何帮助都非常感激。
try this 尝试这个
ng-click="send($event, foods.cal)"
$scope.send = function(event, i) {
event.preventDefault();
// do something with 'i'
$location.path('/calc');
}
instead of $location.path('/calc')
use $state.go('tab.calc')
而不是$location.path('/calc')
使用$state.go('tab.calc')
Try this: 尝试这个:
app.config(function($routeProvider) {
$locationProvider.html5Mode(true);
});
And try adding a base tag to your html head. 并尝试在html头部添加基本标记。 http://www.w3schools.com/tags/tag_base.asp http://www.w3schools.com/tags/tag_base.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.