php - AngularJS automated routes -


i use lightweight php framework @ job uses mvc architecture, url's built /controller/action/. in between using same php framework , angularjs + rest api in project start developing on free time. i've familiarized myself basics of angularjs , built structure + authentication tokens.

i created route splitting window.location.href, when controller needs parameters, should wildcard. can done? or stuck manually creating route params?

.when('/' + controller + '/' + action, {         templateurl: '/assets/layouts/' + controller + '/' + action+ '.html',         controller: controller + methodpath     }) 

edit: controller not nescessary if init in view element, methodpath method first letter capitalized creating controller usersregister, path /users/register

well, figured out. find out rest of path , include them in when. rough example , should extended set default method if 1 not found, such main or index.

var location = window.location.href; var arguments = location.split('/');  if(arguments.length > 4) {     var module = arguments[3];     var method = arguments[4];      var methodpath = method.charat(0).touppercase() + method.slice(1); }  var routeparams = [];  for(var = 5, x = 0; < arguments.length; i++, x++) {     var argument = ':param' + x;     routeparams.push(argument); }  routeparams = routeparams.join('/');  $routeprovider.     when('/' + module + '/' + method + '/' + routeparams, {         templateurl: '/assets/layouts/' + module + '/' + method + '.html',         controller: module + methodpath     }) 

now can access parameters in controller

usersmodule.controller('usersregister', function($scope, $rootscope, $routeparams) {      $scope.uid = $routeparams.param0;  } 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -