这是我的 HTML 文件。当我运行 HTML 页面时,它显示错误,“无法读取未定义的属性‘split’”
<!DOCTYPE html>
<html>
<head>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script>
<script>
var appModule=angular.module('appModule',[]);
appModule.filter('removeDashes',function(){
return function(text){
if(text!==undefined){
return text.split('-').join(' ');
}
}
});
appModule.controller('someCTRL',function($scope){
});
</script>
</head>
<body ng-app="appModule" ng-controller="someCTRL">
<input type="text" model="someDashedText">
<p>
{{someDashedText | removeDashes}}
</p>
</body>
</html>
原文由 Abhishek 发布,翻译遵循 CC BY-SA 4.0 许可协议
在我看来,上面的条件应该用下面的代码代替
此条件检查所有即已定义的、不为空且不为空的字符串。
希望这可以帮助。