2014-05-14 8 views
1

저는 피드 형 앱 (ionic SDK : cordova/angular)을 만들고 있습니다. 앱이 비동기 API 엔드 포인트에서 HTML 기반 메시지를로드합니다. 내가 포함 된 앵커 href를 변환하거나 붙잡는 방법은 무엇입니까? 그래서 나는 그들을 "_system"새로운 윈도우로 변형시킬 수 있습니다. 각도 비동기 콘텐츠의 Cordova window.open "_system"

나는 (간체) 모델을 연결 :

<article ng-repeat="post in posts"> 
    <p ng-bind-html="post.html"></p> 
</article> 

내 비동기 API 논리가 :

$scope.posts = Api.one("channels", channel.id).getList("posts").$object; 

을 ... 그리고 내 지시가 :

app.directive('a', function() { 
    return { 
     restrict: 'E', 
     link: function(scope, elem, attrs) { 

      console.log("a href identified"); 

      // Do the window.open(attrs.href, '_system'); stuff... 
     } 
    }; 
}); 

이 지침을 동적으로로드 된 HTML에는 응답하지 않습니다.

답변

1

ng-bind-html은 HTML 콘텐츠를 컴파일하지 않으므로 문서에 바로 추가됩니다.

.directive('myOwnBinder', function($compile, $timeout){ 
    return { 
     restrict: 'E', 
     scope: { 
     source: '=' 
     }, 
     link: function(scope, element, attrs) { 
     scope.$watch('source', function(newVal, oldVal) { 
      if (newVal === oldVal) return; 
      element.html(newVal); 
      $compile(element.contents())(scope); 
     }); 
     } 
    } 
}) 

을 ... 그래서 같이 사용할 수 :

대신를 사용하는 자신의 바인더를 만들

<my-own-binder source="link"></my-own-binder> 

Working Plunker

+1

건배, 마크를. 당신의 데모는 나를 올바른 길로 인도 해주었습니다. Angularjs가 백 보니 스 (Backbonejs)에서 오는 머리를 망가 뜨리는 경향이 있음을 인정해야합니다. –