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

Popular posts from this blog

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

formula - R: how to pass in a reference to the variable in glm or lm? -