我知道这是一个愚蠢的问题,但我无法让我的范围变量出现在我的指令模板上。我有一个$ scope.strans从$ http请求中获取数据。但是,$ watch服务无法检测指令链接中的更改并将其更新到模板。
App Directive
app.directive('ptransaction',function(){
return{
restrict: 'EAC',
template: '<h3>Did the client arrive? <% strans %><span id="queue_no"> //doesn't update</span></h3>',
link: function($scope){
$scope.$watch('strans ',function(nv,ol){
console.log("changes made"+nv); //cannot see changes in strans
)};
}
};
});
控制器
$scope.Call = function(trans_id){
$http({
url: $locationProvider + 'query_stransaction',
method: "GET",
params: { trans_id: trans_id }
}).success(function (data){
$scope.strans = data.transactions['q_number'];//Cannot update the strans in directive
})
}