大佬教程收集整理的这篇文章主要介绍了angularjs – TypeError:无法读取未定义的属性“replace”,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
TypeError: CAnnot read property 'replace' of undefined at bd (angular.js:10555) at Object.<anonymous> (angular.js:11403) at l.$get.l.$digest (angular.js:14222) at l.$get.l.$apply (angular.js:14493) at angular.js:1449 at Object.e [as invoke] (angular.js:4182) at d (angular.js:1447) at sc (angular.js:1467) at Jd (angular.js:1361) at HTMLDocument.<anonymous> (angular.js:26086)
angular.js中的该段是:
10554 function trimEmptyHash(url) { 10555 return url.replace(/(#.+)|#$/,'$1'); 10556 }
路由文件:
(function(){ 'use Strict'; angular .module('app') .config(routes); routes.$inject = ['$stateProvider','$LOCATIOnProvider']; function routes($stateProvider,$LOCATIOnProvider) { // Configure app states $stateProvider .state('app',{ abstract: true,templateUrl: 'modules/app/app.html',controller: 'AppController' }) .state('app.home',{ url: '/',templateUrl: 'modules/home/index.html' }); $LOCATIOnProvider.html5Mode(true); } })();
我在html中设置了基本的URL:
<base href="/app/" />
this.$$parseLinkUrl = function(url,relHref) { if (relHref && relHref[0] === '#') { // special case for links to hash fragments: // keep the old url and only replace the hash fragment this.hash(relHref.slice(1)); return true; } var appUrl,prevAppUrl; var rewrittenUrl; if ((appUrl = beginsWith(appBase,url)) !== undefined) { prevAppUrl = appUrl; if ((appUrl = beginsWith(basePrefix,appUrl)) !== undefined) { rewrittenUrl = appBaseNoFile + (beginsWith('/',appUrl) || appUrl); } else { rewrittenUrl = appBase + prevAppUrl; } } else if ((appUrl = beginsWith(appBaseNoFile,url)) !== undefined) { rewrittenUrl = appBaseNoFile + appUrl; } else if (appBaseNoFile == url + '/') { rewrittenUrl = appBaseNoFile; } if (rewrittenUrl) { this.$$parse(rewrittenUrl); } return !!rewrittenUrl; };
在我的情况下,最终的“if”子句没有触发对$$解析的调用,因为“rewrittenUrl”从来没有得到一个值,因为中间的if / else if子句都没有解决为true.在我的情况下,这是因为我用于提供应用程序(CompanyName / admin.html)的URL实际上高于我为应用程序设置的基准Href(CompanyName / admin /),因此没有条件解决为true .一旦我将基准Href更改为CompanyName /,我就不再遇到这个问题.
或者,您可以在位置原型上初始化$$absUrl,或者从Angular – watch this issue等待某种修复,并查看joelmdev于3月30日提出的解决方法.
以上是大佬教程为你收集整理的angularjs – TypeError:无法读取未定义的属性“replace”全部内容,希望文章能够帮你解决angularjs – TypeError:无法读取未定义的属性“replace”所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。