AngularJS 未知类型错误:无法读取 null 的属性“1”
AngularJS Unknown TypeError: Cannot Read Property '1' Of Null
下面是我遇到问题的代码:
//Main Codes for the Diary App
(function () {
//Create a new diary app
var diary = angular.module('diary', ['ngRoute']);
//Define a Router for the App
diary.config(function ($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'partials/wall.php',
controller: 'DiaryWallController'
}).
when('/images', {
templateUrl: 'partials/images.html',
controller: 'DiaryImagesController'
}).
when('/audio', {
templateUrl: 'partials/audio.html',
controller: 'DiaryAudioController'
}).
otherwise({
redirectTo: '/'
});
});
//Define Controllers
diary.controller('DiaryWallController', function($scope) {
$scope.message = "Lets do this!! Wall of this site";
});
diary.controller('DiaryImagesController', function($scope) {
$scope.message = "Lets do this!! Images of this site";
});
diary.controller('DiaryAudioController', function($scope) {
$scope.message = "Lets do this!! Audio of this site";
});})();
我收到此未知类型错误:无法读取 NuLL 的属性"1"。它成功获取路由中指定的文件,但不显示在站点中。我已经检查了控制台:
XHR finished loading: GET "http://localhost/mobile%20diary/app/partials/images.html".
但是加载的页面的内容不会显示在网站中。我签入资源并在那里加载图像.html文件,我可以看到文件预览,但它没有显示在站点中。
下面是 HTML Shell 文件:
<!DOCTYPE html>
<html ng-app="diary">
<head lang="en" ng-controller="">
<meta charset="UTF-8">
<link rel="stylesheet" href="css/bootstrap.css" type="text/css">
<link rel="stylesheet" href="css/style.css" type="text/css">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title></title>
</head>
<body>
<header>
<nav class="menu-nav">
<ul>
<li class="menu-buttons"><a href="#" id="selected"><i class="fa fa-newspaper-o"></i></a></li>
<li class="menu-buttons"><a href="#images"><i class="fa fa-file-text-o"></i></a></li>
<li class="menu-buttons"><a href="#audio"><i class="fa fa-image"></i></a></li>
<li class="menu-buttons"><a href=""><i class="fa fa-microphone"></i></a></li>
<li class="menu-buttons"><a href="" id="selected"><i class="fa fa-navicon"></i></a></li>
</ul>
</nav>
</header>
<div ng-view>
</div>
<script src="js/angular.js"></script>
<script src="js/angular-route.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>
我也有同样的错误,类似于@ChanX的评论,我在ng控制器属性中遇到了错误。 就我而言,我不小心将一个 css 类的名称错误地添加到 ng-controller 属性中,我打算将其放入类属性中。
我的假设是,每当解析 ng-controller 属性时出现问题时,您都可能会看到此错误。 无论如何,我当然很高兴我在 SO 上找到了这个,因为它是一个真正的令人头疼的问题。 如果错误消息信息量更大,那就太好了。
这似乎是因为您使用的是本地主机网址。可能适用于调试或开发环境。
content_script.js上有一个函数如下:
function scanLinks() {
var current_domain = document.location.href.match(/^https?:'/'/(?:www'.)?([^'.]+'.[^'/]+)/i);
$("a[href][muse_scanned!=true]").each(function(i) {
this.setAttribute("muse_scanned", true);
var href = this.href;
var domain = href.match(/^http:'/'/(?:(?:www'.)?(?:[^'.]+'.(notlong'.com|qlnk'.net|ni'.to|lu'.to|zzang'.kr)|([^'.]+'.[^'/]+)))/i);
if (domain) {
domain = domain[1] || domain[2] || false;
}
if ((domain != current_domain[1]) && (expandSvcList.indexOf(domain) > -1)) {
this.title = "Expanding URL...";
expandLink(this);
}
});
}
重要的部分是:
var current_domain = document.location.href.match(/^https?:'/'/(?:www'.)?([^'.]+'.[^'/]+)/i);
这将检查您当前的链接,在您的情况下为"http://localhost/..."对于有效的网址,例如"http://www.localhost/"。因为不是这种情况,所以它在访问current_domain[1]
时会导致错误,因为current_domain
为 null。
相关文章:
- 无法获取属性'selectedIndex'的未定义引用或null引用
- delete在Object上效率低下,但在DOM Element's的数据属性,与null out相比
- 未捕获的类型错误:无法读取属性'addEventListener'的null chrome扩展名
- 未捕获的类型错误:无法读取属性'状态'在react中为null
- Javascript Float32数组抛出无法读取属性'0'即使数组定义良好,也为null
- 未捕获的类型错误:无法设置属性'innerHTML'如果为null,则将脚本移动到正文不会;不起作用
- 我该如何解决这个问题?“未捕获的类型错误:无法读取 null 的属性'appendChild'”
- 无法设置属性'innerHTML'在javascript中为null
- 如何计算一个对象中五个属性中有多少是非null的
- Microsoft JScript运行时错误:无法获取属性'的值;样式':对象为null或未定义
- VM5111:1249未捕获类型错误:无法读取属性'x'为null
- 节点的ownerDocument属性为null
- 无法获取属性'字符串'的未定义或null引用IE 11 ASP.NET
- 无法读取属性'addEventListener'菜单上为null的
- Catch无法读取null的属性
- jQuery NaN表单需要NULL属性
- HTML 错误无法设置 null 属性(匿名函数)
- node/angular js如何在对象数组中查找null属性
- 如何检测多级对象是否具有未定义或null属性
- 为什么尝试访问 null 属性会导致某些语言出现异常