Reputation:
I am trying to create a food planner that allows the user to input their meals. They access it through fixed monday-sunday buttons, and the url looks like:
#/planner/Monday/add-meal
I am trying to create new objects to an array that takes:
$scope.meal = {
day: [THE DAY IN THE URL],
title: '',
description:''
};
Do I need to use $root service?
I'm using the Ionic framework. Any help would be greatly appreciated.
Upvotes: 0
Views: 59
Reputation: 48807
In your router, use the following URL for the state:
/planner/:dayOfWeek/add-meal
Then, in your controller, inject $stateParams
:
.controller("TheController", ["$scope", "$stateParams", function ($scope, $stateParams) {
$scope.meal = {
day: $stateParams.dayOfWeek,
title: '',
description:''
};
}]);
See https://github.com/angular-ui/ui-router/wiki/URL-Routing#url-parameters.
Upvotes: 1