angularjs范围不是UI结合 [英] angularjs binding in scope not in ui
本文介绍了angularjs范围不是UI结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的jQuery插件fancytree在我angularjs
我试图用激活事件调用$范围内的功能。
如果我的断点code - 它看起来不错,但其在HTML不显示
i am using jquery fancytree plug in in my angularjs and i am trying to use the 'activate' event to call a function inside the $scope. if i breakpoint the code - it looks good , but its not showing in the html.
这是我的code:
app.controller('ctrl', ['$scope', 'treeSvc', function ($scope, treeSvc) {
$scope.selectedNode = null;
$scope.SetSelectedNode = function(newNode){
$scope.selectedNode = newNode;
//a break point here shows that $scope.selectedNode is really changing but its not showing in the html. calling this function outside the fancy tree - works.
}
treeSvc.get()
.then(function (response) {
$("#tree").fancytree({
source: response.data,
activate: function(event, data) {
$scope.SetSelectedNode(data.node);
}
});
},
function () {
alert('error getting tree data');
});
}]);
HTML
{{selectedNode | json}}
任何想法,为什么?
any ideas why?
推荐答案
当你触发事件外的角度,你需要手动刷新范围:
As your event is fired "outside" of angular, you need to refresh the scope manually :
$("#tree").fancytree({
source: response.data,
activate: function(event, data) {
$scope.SetSelectedNode(data.node);
$scope.$apply();
}
});
在这里看到更多的相关信息: https://docs.angularjs.org/guide/scope
这篇关于angularjs范围不是UI结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文