我在我的angularjs中使用jquery fancytree插件,并且尝试使用'activate'事件来调用$ scope中的函数。如果我断点代码-看起来不错,但未在html中显示。
这是我的代码:
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}}
有什么想法吗?
由于事件是在angular的“外部”触发的,因此您需要手动刷新范围:
$("#tree").fancytree({
source: response.data,
activate: function(event, data) {
$scope.SetSelectedNode(data.node);
$scope.$apply();
}
});
请参阅此处以获取更多信息:https : //docs.angularjs.org/guide/scope
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句