2013-03-26 68 views
3

我想要显示通过角度呈现的标题。它适用于Chrome或Firefox等浏览器以及互联网9和10.在Internet Explorer 8中的标题标记中的角度表达不起作用

ng-app在html标记中定义。

标题标签看起来是这样的:

<title>  
{{resultListQuery.selectedPropertiesSummary}} in {{resultListQuery.geoCodingResult.locationName}} 
</title> 

谁能帮助我吗?你需要更多关于应用程序的信息吗?

+0

最坏的情况下可能会从控制器更改标题=>'angular.element( '标题')。文本(VAR1 + '在' + VAR2)' – charlietfl 2013-03-26 11:16:35

回答

0

你必须使用:

<title ng-bind-template="foo {{pageTitle}} bar"></title> 

另外,您也可以使用ng-bind,但ng-bind-template具有额外的优势,它可以让你有内的多个{{}}表达式。

+0

不要为我 – Maxence 2014-06-25 14:13:19

+0

工作,我已经修复了一个错字,请你再试一次吗? – 2014-06-25 14:17:07

+0

不要使用ng-bind和ng-bind-template – Maxence 2014-06-26 18:42:26

5

您可以使用$window.document.title来设置您的标题没有绑定。

+0

这是不幸的这个答案有一个负面评论,当它实际上唯一的一个是正确的! {{...}}在IE8中失败(以及ng-bind-template或ng-bind)来更新头文件,但是$ window.document.title可以在所有浏览器中使用。 – 2014-06-27 12:09:11

1

这是跨浏览器的解决方案。 ng-bind和ng-bind-template将永远不会工作,因为它们使用element.text(),它永远不会在IE8上工作。

myModule.run(function($interpolate, $window) { 
    ... 
    $rootScope.$watch(function() { 
     return $interpolate(myTitleTemplate)($myScope); 
    }, function(title) { 
     $window.document.title = title; 
    }) 
    ... 
}); 
相关问题