【问题标题】:console.log always printing same thing when code is different in Angular 1 app当 Angular 1 应用程序中的代码不同时,console.log 总是打印相同的东西
【发布时间】:2018-02-20 04:33:51
【问题描述】:

我正在尝试完成这个 YouTube 系列中的 Angular 1.5 教程:Angular 1.5 tutorial。 Angular 1,因为我的工作仍在使用它,我需要使用它变得更好。

问题如下:我创建了一个 blog-list.component.js 和 blog-list.module.js 文件以及一个 app.module.js 文件。我在组件文件中写了一条console.log() 消息,基本上是console.log("hello sir");,但以前我有console.log("hello");。现在,每当我尝试更改 console.log 消息时,它只是控制台记录你好,而不是更新的控制台消息。我不确定我做错了什么,但我似乎无法找到我的错误。也许你能看到它?以下是文件内容:

blog-list.component.js:

'use strict';

angular.module('blogList').
  controller('BlogListController', function() {
    console.log("hello sir");
  }); 

blog-list.module.js:

'use strict';

angular.module('blogList', []);

app.module.js:

'use strict';

angular.module('try', ['blogList']);

index.html 文件:

<!DOCTYPE html>
<html ng-app='try'>
  <head>
    <meta charset="utf-8">
    <title>Let's Build Angular!</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.min.js" type="text/javascript"></script>

    <script src="./js/app/app.module.js"></script>
    <script src="./js/app/app.config.js"></script>

    <script src="./js/app/blog-list/blog-list.module.js"></script>
    <script src="./js/app/blog-list/blog-list.component.js"></script>
  </head>
  <body>
    <input type="text" ng-model='name'>
    <h2>This is going to be a working Angular Page for <span ng-if="name">{{ name }}</span><span ng-if="!name">WoRlD</span></h2>

    <div class='' ng-controller='BlogListController'>
    </div>
  </body>
</html>

我觉得这个错误真的很愚蠢,但我就是看不出来。非常感谢您的帮助!

【问题讨论】:

  • 您是否清除了网络浏览器缓存,您的脚本可能会被缓存,从而拉取旧版本。
  • 如果不是上面的,那你是怎么服务这个东西的?
  • 是的,我已经尝试清除缓存,并且我还在 Chrome 中使用隐身模式启动了该应用程序。我在我的 Mac 上使用“python -m SimpleHTTPServer 8080”为它提供服务。
  • 您是否有运行构建脚本来生成浏览器看到的 HTML 文件?也许你需要再次运行它。它可以是类似npm run buildnpm run gulp build-devnpm start 的命令。
  • Angular 不是在浏览器中运行吗?我在上面列出了所有文件,我已经尝试重新启动服务器了吗?

标签: javascript angularjs console.log


【解决方案1】:

听起来更像是缓存问题而不是任何东西, 您是否尝试打开 chrome 开发人员选项并单击网络 -> 禁用缓存 然后是 ctrl + f5

【讨论】:

  • 是的,我已经尝试清除缓存,并且我还在 Chrome 中使用隐身模式启动了该应用程序。 Chrome 和 Safari 也会发生同样的事情
猜你喜欢
  • 2018-03-22
  • 2011-03-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-30
  • 1970-01-01
  • 2023-04-02
  • 1970-01-01
相关资源
最近更新 更多