-1
我添加了一個指令的兩個實例,但當它們在加載ajax請求時執行時,只有寄存器是ONE ajax請求,但在控制檯中讀取時有兩個執行console.log但結果相同,但後端假設提供隨機結果。指令實例共享Ajax結果,但我不希望它們
我希望假設有2個Ajax請求,但有不可能產生相同結果的機會,但它沒有發生,它們共享結果。
這裏是指令:
app.directive( '人文化',函數($ HTTP) {
return {
restrict:"EA",
template:'template stuff',
replace: true,
transclude: 'element',
scope:{
key:"=",
activate:"=",
theme:"@"
},
link:function (scope, elem, attrs) {
scope.question="";
scope.placeholder="";
scope.answer="";
scope.key="";
var temp_key;
$http({ url:stage.ajax_url,method: "GET",params: {'action':'do_ajax','fn':'human'}}).success(function(data) {
scope.question=data.question;
scope.placeholder=data.placeholder;
temp_key=data.key;
console.log(temp_key);
});
}
}
});
我在這裏做錯了什麼?我需要指令的多個實例有不同的ajax結果...