javascript - How to get ui-router state params? -
i trying create food planner allows user input meals. access through fixed monday-sunday buttons, , url looks like:
#/planner/monday/add-meal
i trying create new objects array takes:
$scope.meal = { day: [the day in url], title: '', description:'' };
do need use $root service?
i'm using ionic framework. appreciated.
in router, use following url state:
/planner/:dayofweek/add-meal
then, in 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.
Comments
Post a Comment