1

HTML コード:

<div class="test">{{name}}</div>

角度コード:

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

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
});

app.directive('test', function(){
  return {
    restrict: 'C',
    link: function(scope, elm, attrs){
      var content = elm.html();
      alert(content);
    }
  }
});

文字列を警告します{{name}}。レンダリングされた文字列を警告する方法はWorld?

ライブデモ: http://plnkr.co/edit/Mov0AlkdE9B8yKiBjpnp?p=preview

4

1 に答える 1

5

これを行うには$interpolateサービスを使用する必要があります

app.directive('test', function($interpolate){
  return {
    restrict: 'C',
    link: function(scope, elm, attrs){
      var content = elm.html();
      alert($interpolate(content)(scope))
    }
  }
});

デモ:フィドル

于 2013-03-28T03:30:49.867 に答える