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

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -