Kylee
Kylee

Reputation: 1675

AngularJS data binding/templating not working in IE 8

UPDATE:

So, it appears this is an issue with IE and javascript updating the title element. With that in mind, does anyone know how to fix that issue? As of right now I don't have an answer to accept for this question so might as well get to the bottom of this.

ORIGINAL QUESTION:

I've really been digging in to AngularJS recently and loving it. I'm running in to a major issue however. The data binding/templating is not working in IE 8. I'm setting a variable called $scope.pageTitle in my MainController and it works in Chrome and Firefox. In IE 8 it displays as {{pageTitle}} in the title bar and I can't find any information on how to fix this. Its driving me nuts. Can anyone help or point me to a resource I may have over looked? If really needed I can make a jsfiddle as an example.

Here is the top of my index.html:

<!DOCTYPE html>
<html lang="en" ng-app="App" ng-controller="MainController">
    <head>
        <!-- Vendor JS Libraries -->
        <script type="text/javascript" src="lib/angular.js"></script>
        <script type="text/javascript" src="lib/underscore-min.js"></script>
        <script type="text/javascript" src="lib/jquery.js"></script>
        <!-- Bootstrap JS & CSS -->
        <script type="text/javascript" src="lib/bootstrap/js/bootstrap.js"></script>
        <link rel="stylesheet" type="text/css" href="lib/bootstrap/css/bootstrap.css">
        <!-- Lightbox  JS & CSS-->
        <script type="text/javascript" src="lib/lightbox/js/lightbox.js"></script>
        <link rel="stylesheet" type="text/css" href="lib/lightbox/css/lightbox.css">
        <!-- Application resources -->
        <script src="static/app.js"></script>
        <link rel="stylesheet" type="text/css" href="static/app.css">

        <title>{{pageTitle}} &ndash; Site Name</title>
    </head>

and my app.js:

//AngularJS stuff
angular.module('App', []).
    config(function($routeProvider)
    {
        $routeProvider.
            when('/home', {templateUrl:'templates/home.html', controller:HomeController}).
            otherwise({redirectTo:'/home'})
    });

function MainController($scope){
    $scope.pageTitle = 'Default';

    $scope.setPageTitle = function(pageTitle){
        $scope.pageTitle = pageTitle;
    }
}

function HomeController($scope){
    $scope.setPageTitle('Home');
}

Upvotes: 0

Views: 2801

Answers (1)

Kylee
Kylee

Reputation: 1675

Thought I would post and answer since it came in the form of a comment. This appears to be an issue with IE and modifying the title tag with in Javascript. I solved this by using IE conditionals

<!--[if !IE]> -->
<title>{{pageTitle}} &ndash; Site Title</title>
<!-- <![endif]-->

<!--[if IE]>
<title>Site Title</title>
<![endif]-->

Not ideal but it works.

Upvotes: 2

Related Questions