我想忘記「jQuery」,因爲我喜歡「AngularJS」。但是,我需要知道如何在我的應用程序中使用將AngularJS合併到別處的獨立任務。 在這種情況下,我想使用「$ https AngularJS」函數導入一個JavaScript文件,例如。
例(它用於做jQuery的):
$.get("url.js", function(data){ eval(data) }); //ok
console.info($.get); //code code code... ok
例
//In a controller
App.controller('Ctrllr', ['$http', function ($http) {
$http.get("url.js").success(function(data){
eval(data); //ok
});
console.info($http); //code code code.... ok
})
//outside
$http.get("url.js"); //$http is undefined
//How to use $http here?
正如你在最後一次通話看到(AngularJS記錄),$ HTTP是在一個過程之外。現在,想知道如何在控制器/應用程序之外使用類$ http或另一個Angular utils?
您被外界是什麼意思?控制器加載之前?哪個事件與角度上下文有關? – micha 2015-02-07 13:35:11
加載控制器之前 – 2015-02-07 15:00:32
提供的答案不能滿足您的要求嗎? – ribsies 2015-02-07 17:28:47