skip to Main Content

What’s the best way to do something like this in AngularJS without data binding?

document.getElementById('divid').value = 'Change Text to This';

I know I can achieve it with {{value}} but I have default values for SEO purpose and hence I need to change it without binding, for example,

<div id="divid">Default text</div>

Thanks

3

Answers


  1. you can do data binding for this {{}} also you can use ng-bind.

    Login or Signup to reply.
  2. In angular you can fetch an element using angular.element()

    In your case, Try

    var ele = angular.element('#wrapper');
    $compile(ele);
    

    For this to work you need to inject $compile.

    Login or Signup to reply.
  3. You can use translate function:

    <div id="divid">{{ _("Default text") }}</div>
    

    function:

    $.scope._ = function(text) {
        return 'Change Text to This';
    };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search