gpt4 book ai didi

angularjs - 无法读取AngularJS中未定义的属性 'replace'?

转载 作者:行者123 更新时间:2023-12-03 08:15:54 24 4
gpt4 key购买 nike

我正在使用表情符号过滤器,但收到错误消息“无法读取未定义的属性‘替换’”

错误是:

TypeError: Cannot read property 'replace' of undefined
at g.<anonymous> (file:///C:/xampp/htdocs/web_UI/js/emoji.min.js:1:10531)
at e (file:///C:/xampp/htdocs/web_UI/js/angular.min.js:155:305)
at Ia.| (file:///C:/xampp/htdocs/web_UI/js/angular.min.js:143:248)
at Object.A.constant [as get] (file:///C:/xampp/htdocs/web_UI/js/angular.min.js:154:212)
at g.$digest (file:///C:/xampp/htdocs/web_UI/js/angular.min.js:98:307)
at g.$apply (file:///C:/xampp/htdocs/web_UI/js/angular.min.js:101:157)
at HTMLAnchorElement.<anonymous> (file:///C:/xampp/htdocs/web_UI/js/angular.min.js:177:65)
at HTMLAnchorElement.m.event.dispatch (file:///C:/xampp/htdocs/web_UI/js/jquery.min.js:3:8436)
at HTMLAnchorElement.r.handle (file:///C:/xampp/htdocs/web_UI/js/jquery.min.js:3:5146)

HTML 代码:

<div class="row" ng-repeat="n in q.answers"  ng-bind-html = " n | emoji">

json 响应:

{
"data":[
{
"id":10,
"title":"what is internet?",
"userID":2,
"question":"what is internet?",
"viewed":0,
"votes":5,
"answers":[
{"id":15,
"questionID":10,
"userID":2,
"answer":"search on google ....:)",
"correct":"0",
"votes":7

},
{
"id":47,
"questionID":10,
"userID":2,
"answer":"test :smiley:",
"correct":"0","votes":0,
}
]}
]
}

js函数:

QAApp.controller('askbyctrl', function ($scope, $http){
$http.get(server + 'api').success(function(data) {
/*console.log(data);*/
$scope.qa = data;
});
$scope.select = function(item) {
/*console.log(item);*/
$scope.selected = item
}
$scope.isSelected = function(item) {
return $scope.selected == item
}
});

然后在 html 中使用ng-repeat="q in qa.data"作为答案,并使用n in q.answers"来显示答案

请告诉我如何解决?

Plunker link

最佳答案

这是工作代码...

            angular.module("app", ['emoji', 'ngSanitize']).controller("AppCtrl", function ($scope) {
$scope.messages = [
"Animals: :dog: :cat: :snake:",
"People: :smile: :confused: :angry:",
"Places: :house: :school: :hotel:"
];
});


<body ng-app="app" ng-controller="AppCtrl">
<ul>
<li ng-repeat="message in messages" ng-bind-html="message | emoji"></li>
</ul>
</body>

关于angularjs - 无法读取AngularJS中未定义的属性 'replace'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25379439/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com