2015-05-07 83 views
1

我已經註冊到付費版本的Polldaddy,並提供了此腳本標記(減去正確的id)。在角度html視圖中加載外部腳本

<script type="text/javascript" charset="utf-8" src="http://static.polldaddy.com/p/0000000.js"></script> 

該腳本必須在我的視圖中的div中加載 - 並且它不工作。角度在視圖中加載腳本有問題嗎?可能嗎?如果是這樣,你能幫我理解怎麼做嗎?

讓我知道你是否需要更多信息。

感謝

+0

你想從partial..then加載腳本簡單地將不可能 –

+0

是的,我想加載腳本視圖html內的元素。爲什麼這是不可能的,是否有解決方法? – CarlTaylor1989

+0

看看這個,使用指令..我不知道https://gist.github.com/endorama/7369006 –

回答

2

不能加載腳本到期的角度script指令的角內部應用程序,所以你需要創建自己的指令。 事情是這樣的:

function polldaddy() { 
    var injectScript = function(element) { 
     var scriptTag = angular.element(document.createElement('script')); 
     scriptTag.attr('charset', 'utf-8'); 
     scriptTag.attr('src', 'http://static.polldaddy.com/p/0000000.js'); 
     element.append(scriptTag); 
    }; 

    return { 
     link: function(scope, element) { 
      injectScript(element); 
     } 
    }; 
} 

angular 
    .module('myApp') 
    .directive('polldaddy', polldaddy); 

,然後在你的HTML:

<div polldaddy></div> 
+0

感謝您的回覆 - 這不幸沒有做任何事情:( – CarlTaylor1989

+0

@ CarlTaylor1989你是對的,我didn 't test the code,sorry。Now we sure it works,sorry again。 – rpadovani

+0

Thank you that works。但是我現在有一個單獨的問題,不喜歡交叉原點域腳本!我相信沒有辦法繞過嗯... – CarlTaylor1989