繁体   English   中英

console.log不在Chrome中打印任何内容

[英]console.log not printing anything in Chrome

任何人都可以解释为什么console.log突然停止工作? 我正在尝试为Angularjs类调试练习,并且在某个时刻,console.log不再打印任何东西了。 我用chrome和我的缓存很清楚。

编辑:在这个片段和Firefox中,console.log()可以正常工作但在Chrome中没有。 怎么会?

 (function () { 'use strict'; angular.module('Ass3', []) .controller('NarrowItDownController', Narrowdown) .service('MenuCategoriesService', MenuCategoriesService); Narrowdown.$inject = ['MenuCategoriesService']; function Narrowdown(MenuCategoriesService){ var nrdown = this; var promise = MenuCategoriesService.getMatchedMenuItems(); } MenuCategoriesService.$inject = ["$http"] function MenuCategoriesService($http){ var service = this; console.log("start"); service.getMatchedMenuItems = function(searchTerm){ return $http({ method : 'GET', url: ("https://davids-restaurant.herokuapp.com/menu_items.json") }).then(function(result){ var foundname = []; angular.forEach(result.data.menu_items, function(value, key){ var name = value.name; //console.log(typeof name); if (name.toLowerCase().indexOf("chicken") !== -1){ foundname.push(name); }; }); console.log("end"); return foundname; }); } } })(); 
 <!doctype html> <html lang="en" ng-app='Ass3'> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" ></script> <script type="text/javascript" src="app.js"></script> <title>Narrow Down Your Menu Choice</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="styles/bootstrap.min.css"> <link rel="stylesheet" href="styles/styles.css"> </head> <body> <div class="container" ng-controller="NarrowItDownController as nrdown"> <h1>Narrow Down</h1> <div class="form-group"> <input type="text" placeholder="search term" class="form-control"> </div> <div class="form-group narrow-button"> <button class="btn btn-primary">Narrow It Down For Me!</button> </div> <!-- found-items should be implemented as a component --> <found-items found-items="...." on-remove="...."></found-items> <ul> <li ng-repeat="category in nrdown.categories"> {{categroy.name}} </li> </ul> </div> </body> </html> 

您在return语句后放置了日志

return foundname;
console.log("end");

只需像这样交换这些行

console.log("end");
return foundname;

return foundname; 应该在console.log()下面

 (function () { 'use strict'; angular.module('Ass3', []) .controller('NarrowItDownController', Narrowdown) .service('MenuCategoriesService', MenuCategoriesService); Narrowdown.$inject = ['MenuCategoriesService']; function Narrowdown(MenuCategoriesService){ var nrdown = this; debugger var promise = MenuCategoriesService.getMatchedMenuItems(); } MenuCategoriesService.$inject = ["$http"] function MenuCategoriesService($http){ var service = this; console.log("start"); service.getMatchedMenuItems = function(searchTerm){ return $http({ method : 'GET', url: ("https://davids-restaurant.herokuapp.com/menu_items.json") }).then(function(result){ var foundname = []; angular.forEach(result.data.menu_items, function(value, key){ var name = value.name; //console.log(typeof name); if (name.toLowerCase().indexOf("chicken") !== -1){ foundname.push(name); }; }); console.log("end"); return foundname; }); } } })(); 
 <!doctype html> <html lang="en" ng-app='Ass3'> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js" ></script> <script type="text/javascript" src="app.js"></script> <title>Narrow Down Your Menu Choice</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="styles/bootstrap.min.css"> <link rel="stylesheet" href="styles/styles.css"> </head> <body> <div class="container" ng-controller="NarrowItDownController as nrdown"> <h1>Narrow Down</h1> <div class="form-group"> <input type="text" placeholder="search term" class="form-control"> </div> <div class="form-group narrow-button"> <button class="btn btn-primary">Narrow It Down For Me!</button> </div> <!-- found-items should be implemented as a component --> <found-items found-items="...." on-remove="...."></found-items> <ul> <li ng-repeat="category in nrdown.categories"> {{categroy.name}} </li> </ul> </div> </body> </html> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM