search

Home  >  Q&A  >  body text

angular.js - How to get the data-bound value immediately in angularJs?

I want to use the data-bound value immediately:

Get data from Json file and bind it to scope
$scope.abc="hahahah";

<

p class="***" data-value="{{abc}}" skilldetail='' index='0'>
But when getting the data-value from the link function of the directive, I did not get "hahahah", but got {{abc}}

The value of element.find('.***').attr('data-value'); is {{abc}}, not hahahah.

How to do this? When does the value of ng-bing take effect?

伊谢尔伦伊谢尔伦2790 days ago726

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-15 16:56:01

    $scope.apply() tells angular that it’s time to update the data

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-15 16:56:01

    js...
    
    link: function(scope, el, attrs) {
        ...
        scope.$apply(function() {
            // TODO
        });
        ...
    }
    ...
    

    reply
    0
  • Cancelreply