Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度-在标题中使用可选参数_Angularjs - Fatal编程技术网

Angularjs 角度-在标题中使用可选参数

Angularjs 角度-在标题中使用可选参数,angularjs,Angularjs,如何使用标题中我的角度路线中的可选参数 因此,我希望textToSearch出现在标题中: .when('/search/:textToSearch', { title: 'Searching' + textToSearch, templateUrl: 'views/search.html', controller: 'searchController' } ) 我正在routeChangeSuccess中设置标题: $rootScope

如何使用标题中我的角度路线中的可选参数

因此,我希望
textToSearch
出现在标题中:

.when('/search/:textToSearch',
    {
      title: 'Searching' + textToSearch,
      templateUrl: 'views/search.html',
      controller: 'searchController'
    }
  )
我正在routeChangeSuccess中设置标题:

$rootScope.$on('$routeChangeSuccess', function() {
          //Set the <title> tag
          if (!$route.current.title) {
            document.title = 'Default Generic Title';
          } else {
            document.title = $route.current.title;
          }
}
$rootScope.$on(“$routeChangeSuccess”,function()函数){
//设置标签
如果(!$route.current.title){
document.title='默认通用标题';
}否则{
document.title=$route.current.title;
}
}

我会在标题字符串中为路由参数使用占位符,并根据路由参数对象插入它:

.when('/search/:textToSearch', {
  title: 'Searching {{ textToSearch }}',
  templateUrl: 'views/search.html',
  controller: 'searchController'
})
插入部分(确保插入
$interpolate
服务):

$rootScope.$on(“$routeChangeSuccess”,function()函数){
//设置标签
如果(!$route.current.title){
document.title='默认通用标题';
}否则{
document.title=$interpolate($route.current.title)($route.current.params);
}
})

如何使用
title
?像这样?是的,使用routeChangeSuccess-更新代码
title:“搜索{{{textToSearch}}',
似乎不起作用,我测试过;)确保注入$interpolation服务。你有错误吗?啊,是的,忘记注入服务了!
$rootScope.$on('$routeChangeSuccess', function() {
  //Set the <title> tag
  if (!$route.current.title) {
    document.title = 'Default Generic Title';
  } else {
    document.title = $interpolate($route.current.title)($route.current.params);
  }
})