TypeError:$ scope.apply不是一个函数 [英] TypeError: $scope.apply is not a function
本文介绍了TypeError:$ scope.apply不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过rdflib.js
检索联系人列表.它已正确加载,并将其保存在合并范围内的列表中.
I am trying to render the contacts list after retrieving it thru rdflib.js
. It is loading properly and saving it in the list inside the scope.
但是我无法渲染$ scope不更新的正弦,似乎我在错误的地方调用了$scope.apply()
.发生错误是因为我在angular外部调用了它,但是我故意在angular context(nowOrWhenFetched
)外部的函数内部调用了它,所以对我来说没有意义.有帮助吗?
But I am not able to render sine the $scope doesn't update, it seems like I am calling $scope.apply()
in the wrong place. The error occurs because I call it outside angular, but I am deliberately calling it inside the function that is outside angular context (nowOrWhenFetched
), so not making sense for me. any help?
$scope.load = function () {
//$scope.getContactsList();
var g = $rdf.graph();
var f = $rdf.fetcher(g);
f.nowOrWhenFetched($scope.path + '*',undefined,function(){
var DC = $rdf.Namespace('http://purl.org/dc/elements/1.1/');
var RDF = $rdf.Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
var LDP = $rdf.Namespace('http://www.w3.org/ns/ldp#');
//var myOntology = $rdf.Namespace('http://user.pds.org/ontology/');
var VCARD = $rdf.Namespace('http://www.w3.org/2006/vcard/ns#');
var evs = g.statementsMatching(undefined, RDF('type'), VCARD('Individual'));
if (evs != undefined) {
for (var e in evs) {
var id = evs[e]['subject']['value'];
var fullname = g.anyStatementMatching(evs[e]['subject'], VCARD('fn'))['object']['value'];
var email = g.anyStatementMatching(evs[e]['subject'], VCARD('hasEmail'))['object']['value'];
var phone = g.anyStatementMatching(evs[e]['subject'], VCARD('hasTelephone'))['object']['value'];
var contact = {
id: id.slice(id.length-1),
Name: fullname,
Email: email,
Phone: phone
};
$scope.contacts.push(contact);
}
}
$scope.apply();
});
};
推荐答案
函数为$apply()
,带有$
.
这篇关于TypeError:$ scope.apply不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文