angularjs - angular.js: Set own variable in state? -


this how route 2 different url:

.state('cars', {     url: "/cars/:title",     templateurl: 'templates/cars.html',     controller: 'article', }) .state('vegetables', {     url: "/vegetables/:titel",     templateurl: 'templates/vegetables.html',     controller: 'article', }) 

the controller 'article' looks this:

.controller('article', function($scope, $http, $stateparams) {     $http({         method: 'post',         url: "script.php",         data: {'type': type, 'title': $stateparams.title},     }); }); 

my question how set variable type in data of controller? in example type 'cars' or 'vegetables'. can set variable in state part?

.controller('article', function($scope, $http, $stateparams,$state) { $http({     method: 'post',     url: "script.php",     data: {'type': $state.current.name, 'title': $stateparams.title}, }); 

});


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -