报错内容:
TypeError: Cannot read property 'replace' of undefined
TypeError: Cannot read property 'indexOf' of undefined
跳转前页面代码:
跳转前页面controller相关代码:
$scope.linkToDetail=function(msgId) {
$state.go('detail',{'msgId':msgId});
};
详情页html:
{{msgdata.user.name}}
{{msgdata.created_at|formattime}}
![]()
{{msgdata.source|formatsource}}
跳转后的详情页controller:
.controller('detailCtrl', ['$scope','roufanservice','$state','$stateParams',
function($scope,roufanservice,$state,$stateParams){
var msgid=$stateParams.msgId;
var sendData={
token:localStorage.getItem('authorize.token'),
secret:localStorage.getItem('authorize.secret'),
path:'statuses/show.json?format=html&id='+msgid,
param:'{}'
};
var promise=roufanservice.getData(sendData,'get');
promise.then(function(data){
$scope.msgdata=JSON.parse(data.result);
},
function(err){
roufanservice.showErrMsg(err);
});
}]);
详情页的url:
http://localhost:8100/#/detail?msgId=qIsnp6YWOQs
报的错中的replace来自两个filter,其他页面不报错,只要到了详情页就开始报错
.filter('linkformat',function() {
return function(content){
var userlink='';
return content.replace(//g,userlink);
};
})
.filter('formatsource',function(){
return function(source){
if(source.indexOf('href')>0){
return angular.element(source).contents()[0].data;
}
else{
return source;
}
};
})
网上搜了下,可能跟$locationProvider.html5Mode有关,但是看的一头雾水,请大家帮忙解答一下,谢谢!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这个问题最方便的解决方法是在过滤器中加一层判断
不明白为什么页面跳转走了还会报这个错?
你的这个
不是应该在跳转前就渲染过了嘛?
跳转走了为什么还会报filter的错?难道你页面跳转以后又使用了这俩filter? 不太懂~