angularjs - Parse $routeParams in the config object -
i trying dynamically set title each page of angular app. setting title of page in $routeprovider configuration so:
angular.module('app.assets').config(['$routeprovider', function($routeprovider) { $routeprovider. when('/assets/:id', { templateurl: 'app/components/assets/views/view.tpl.html', controller: 'assetviewctrl', data : { pagetitle: 'assets:id' } }); }]);
the problem page title 'assets:id' verbatim. possible parse value of 'id' similar first parameter of when
?
i.e /assets/:id -> assets/1991
.
instead of using data, might want resolve variables:
when('/assets/:id', { templateurl: 'app/components/assets/views/view.tpl.html', controller: 'assetviewctrl', resolve: { data: ['$route', function($route){ var obj = {}; obj.pagetitle = 'assets/' + $route.current.params.id; return obj; }] } }
and in controller, inject 'data' (with no quotes). data object property 'pagetitle' 'assets/' + :id .
note when resolve, have use $route.current.params $routeparams still has previous route according : https://docs.angularjs.org/api/ngroute/provider/$routeprovider
in controller can like:
$scope.title = data.pagetitle
in view can like
<html app="myapp"> <title ng-bind="title"></title> </html>
Comments
Post a Comment