2014-10-02 51 views
0

未來我有一個指令:角指令在JSON

在這裏,我傳遞一個數據對象:

<a-link options = "data"></a-link> 

這裏是我的指令:

.directive('aLink', function() { 
return { 
    restrict: 'AE', 
    replace: true, 
    template: '<a href = "{{href}}">{{text}}</div>', 
    link: function(scope, element, attrs) { 
      scope.$watch('options', function(newValue, oldValue) { 
      if (newValue) 
       scope.href = newValue.href; 
       scope.text = newValue.text; 
      }); 
    } 
}); 

這工作得很好。它給我像

<a href = "/home/login.html">link</a> 

一個錨標記我的問題是:

如果我得到的JSON如下:

{ 
    body : "Click <a-link text = 'here' href = '/home/login.html'></a-link>" 
} 

和我的html:

<p ng-bind-html = "body"></p> 

這doenot工作。

我該如何重新編譯?我是否需要通過其他指令並在那裏編譯它?

回答

0

使用$編譯服務:

$compile(response.body)($scope)