Hi guys,
I thought I was getting the hang of routing in Ionic but I guess I’m still a noob at it.
I’m trying to change a value in one of the $scopes in my .JSON file from true to false when a button is toggled. Right now this is what my button looks like:
<label class="toggle toggle-assertive" ng-controller="FaveCtrl">
<input type="checkbox" ng-model="fave">
<div class="track">
<div class="handle">
</div>
</div>
</label>
Here’s my controller.js:
var dishApp = angular.module('dishApp.controllers', [])
dishApp.factory('dishes', function($http){
function getData(callback){
$http({
method: 'GET',
url: '/json/dishes.json',
cache: true
}).success(callback);
}
return {
list: getData,
find: function(title, callback){
getData(function(data) {
var dish = data.filter(function(entry){
return entry.title === title;
})[0];
callback(dish);
});
}
};
})
.controller('DishesCtrl', function ($scope, dishes){
dishes.list(function(dishes) {
$scope.dishes = dishes;
});
})
.controller('DishCtrl', function ($scope, $stateParams, dishes){
dishes.find($stateParams.dishTitle, function(dish) {
$scope.dish = dish;
});
})
.controller('FaveCtrl', ['$scope', function($scope) {
$scope.fave = true;
}])
.filter('encodeURI', function(){
return window.encodeURI;
});
And here’s an example of my .JSON
[
{
"title": "Chicken with tomatoes & asparagus",
"cat": 1,
"fave": false,
"cook": "30 minutes",
"serves": 4
}
]
If anyone could help explain me the routing or send me somewhere that does that would be so much appreciated. I know this is a total noob question but I’ve looked all over the place and am still confused by Angular/Ionic’s routing.
Thanks so much in advance guys!