1

In the following string, parsing the javascript object and placing it into an ngBinding is not evaluated it. I have a string that I am trying to include an specific part of a javascript object inside of, and am switching over to Angular for the relative ease of usage. The string at present is:

<html ng-app="bindHtmlExample">
...
<div>
    <p>"You owe ${{datatokens["DB.PMT"]}}"</p>

If I place something like "You owe ${{600+11}}" inside of the ngBinding it properly evaluates to:

"You owe me $611"

Also, when I open the console it can accurately locate datatokens["DB.PMT"]. Thus, I must be conceptually missing how to make this javascript object available to this Angular application.

2
  • SHow your entire HTML instead of just a part of it. Commented Aug 12, 2014 at 16:36
  • 3
    if it's not in angular scope, angular can't evaluate it. If your data is in global namespace, pass it into a scope variable Commented Aug 12, 2014 at 16:37

1 Answer 1

3

The {{}} binding operator in angular creates a binding from $scope to view. Any time $scope changes, the view will update based on this binding. It is the shortcut for the ng-bind directive and requires the $scope object to be present . You can use the binding operator in views for evaluating bindings and updating on change. For your case you can use the binding in view as below.

HTML:

<div ng-app='app'>
    <div ng-controller='controller'>
        <div>You owe $ {{ datatokens}} </div>
    </div>
</div>

Javascript:

var app = angular.module('app', []);

app.controller('controller', function ($scope) {   
    $scope.datatokens = 600;
});

This will always update your binding and corresponding view element

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.