Angular.js change ng-click location

I've read some other posts on the same topic, but can't seem to get myself to work. Basically, I want the location of my app to change to an ng-click event. So I have html code that looks like this:

<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 is updated on the home tab as if it can't find "/ calc". I tried calc preceeded by parent folders and followed by file extension but couldn't get this to work. Any help was massively appreciated.

+3


source to share


2 answers


try it

in html

ng-click="send($event, foods.cal)"

      

controller



$scope.send = function(event, i) {
event.preventDefault();
// do something with 'i'

$location.path('/calc');

}

      

you can also try using $ state

instead $location.path('/calc')

use$state.go('tab.calc')

+2


source


Try the following:

app.config(function($routeProvider) {
    $locationProvider.html5Mode(true);
});

      



And try adding a base tag to your html header. http://www.w3schools.com/tags/tag_base.asp

0


source







All Articles