0

I'm having a weird angularjs binding problem

<a class="navbar-brand" href="#">Application (Environment: {{ globalConfig.environment + ""}})</a>

That will work, and render the value "dev"

<a class="navbar-brand" href="#">Application (Environment: {{ globalConfig.environment }})</a>

This doesn't render anything.

<a class="navbar-brand" href="#">Application (Environment: <span ng-bind="globalConfig.environment"></span>)</a>

This last example works.

Any ideas why the second example won't render out the value "dev"?

The controller is as follows:

angular.module('uppApp').controller('globalController', function ($scope) {
    $scope.globalConfig = {
        environment: 'dev'
    };
});

the html looks as follows:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" ng-app="uppApp">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>Pixel Pimp Web UI</title>

    <link href="assets/css/style.css" rel="stylesheet" />

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="assets/thirdparty/ie8mediasupport.js"></script>
    <![endif]-->

</head>
<body ng-controller="globalController">
    <div class="navbar navbar-fixed-top" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">Pixel Pimp (Environment: <span ng-bind="globalConfig.environment"></span>)</a>
            </div>
            <div class="collapse navbar-collapse">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">Dashboard</a></li>
                    <li><a href="#about">Pixel Groups</a></li>
                </ul>
            </div><!--/.nav-collapse -->
        </div>
    </div>

    <div class="container">
        <h1>Dashboard</h1>

        <div id="myfirstchart" style="height: 250px;"></div>
    </div><!-- /.container -->


    <script src="assets/thirdparty/built.js"></script>
    <script src="assets/js/uppangular.js"></script>

    <script>
    $(function () { genGraph(); });
    function genGraph() {
        new Morris.Line({
            // ID of the element in which to draw the chart.
            element: 'myfirstchart',
            // Chart data records -- each entry in this array corresponds to a point on
            // the chart.
            data: [
              { year: '2008', value: 20 },
              { year: '2009', value: 10 },
              { year: '2010', value: 5 },
              { year: '2011', value: 5 },
              { year: '2012', value: 20 }
            ],
            // The name of the data record attribute that contains x-values.
            xkey: 'year',
            // A list of names of data record attributes that contain y-values.
            ykeys: ['value'],
            // Labels for the ykeys -- will be displayed when you hover over the
            // chart.
            labels: ['Value']
        });
    }
    </script>

</body>
</html>

UPDATE

When i wrap the decorate the interpolate service for debugging like this:

app.config(function($provide){
    $provide.decorator("$interpolate", function($delegate){

        var interpolateWrap = function(){
            var interpolationFn = $delegate.apply(this, arguments);
            if(interpolationFn) {
                return interpolationFnWrap(interpolationFn, arguments);
            }
        };

        var interpolationFnWrap = function(interpolationFn, interpolationArgs){
            return function(){
                var result = interpolationFn.apply(this, arguments);
                var log = result ? console.log : console.warn;
                log.call(console, "interpolation of  " + interpolationArgs[0].trim(), 
                                  ":", result.trim());
                return result;
            };
        };

        angular.extend(interpolateWrap, $delegate);
        return interpolateWrap;

    });
});

The console log will show:

interpolation of  {{globalConfig.environment+""}} : dev 

However for the binding of {{globalConfig.environment}} nothing shows up in the console window.

2
  • 1
    works fine here: jsbin.com/tawetawesa/1/edit?html,js,output Commented Oct 18, 2014 at 19:58
  • Yeah. I've never had this issue before. It's really peculiar, there must be something screwed up somewhere in my setup. Commented Oct 18, 2014 at 20:17

1 Answer 1

1

Ok I figured it out. I'm using grunt bake for the first time, and I think grunt bake, is stripping out the {{globalConfig.environment}} code from the rendered file.

Sorry. Stupid mistake.

UPDATE

Ultimately I fixed it by modifying the BAKE parse pattern to use [{ }] instead of {{ }}

bake: {
        build: {
            options: {
                parsePattern: '/\[\{\s?([\.\-\w]*)\s?\}\]/g'
            },
            files: {
                "app/index.html": "app/base.html"
            }
        }
    },
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.