AngularJS Unknown TypeError: cannot read property '1' Of Null

Below is the code that Im is encountering:

//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"; });})(); 

I get this Unknown TypeError: Can't read property '1' NuLL. It successfully extracts the files specified in the route, but it does not appear on the site. I checked the console:

 XHR finished loading: GET "http://localhost/mobile%20diary/app/partials/images.html". 

But the content of the loaded page does not appear on the site. I check the resources and the images.html file is uploaded there, and I see a file view, but it does not appear on the site.

Below is the HTML Shell file:

 <!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> 
+6
source share
2 answers

I also had the same error and looked like a comment from @ChanX I had an error in the ng-controller attribute. In my case, I accidentally added the css class name, which I intended to put into the class attribute in the ng-controller attribute by mistake.

My hypothesis is that you can see this error when there is a problem with parsing the ng-controller attribute. In any case, I am very glad that I found it this way, because it was a real head cleaner. It would be nice if the error message was more informative.

+9
source

It looks like you are using localhost url. Probably for debugging or development environment.

And there is a function content_script.js that looks like this:

 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); } }); } 

Main part:

 var current_domain = document.location.href.match(/^https?:\/\/(?:www\.)?([^\.]+\.[^\/]+)/i); 

This will check your current link, in your case " http: // localhost / ..." for a valid url like "http: // WWW .localhost /". Since this is not the case, it causes an error accessing current_domain[1] , since current_domain is null.

0
source

Source: https://habr.com/ru/post/981253/


All Articles