浏览器未检测到 AngularJS 中的更改 [英] Browser does not detect changes in AngularJS

查看:36
本文介绍了浏览器未检测到 AngularJS 中的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 IDE WebStorm 和 Safari 浏览器开发 AngularJS 应用程序.

Im developing an AngularJS application using IDE WebStorm and Safari browser.

到目前为止一切都运行良好,但我最近将一些 HTLM 封装在我通过指令使用的模板中:

Everything has worked perfectly so far, but I recently encapsulated some HTLM in a template that I use via a directive:

 .directive('referenceValue', [function ($scope) {
    return {
        restrict: 'E',
        templateUrl: "views/citizenprofile/reference/reference.html",
        controller: "referenceValueCtrl"
    }
}])

我以正常方式调用"指令,没什么特别的

I "call" the directive the normal way, nothing fancy <reference-value></reference-value>

当我编辑 reference.html 时,浏览器仅检测在第一次编辑中的更改..如果我再次编辑 reference.html 并更新浏览器,则不会检测到更改.如果我重新启动浏览器,则会再次检测到更改.所以我基本上每次要调试 HTML 代码时都需要重新启动浏览器.每次编辑时都会检测到控制器中的更改.

When I edit the reference.html the browser only detects the changes in the first edit.. If I edit reference.html a second time and update the browser then the change is not detected. If I restart the browser the change is detected again. So I basically need to restart my browser each time I want to debug the HTML code. Changes in the Controller is detected at every edit.

谁能告诉我如何解决这个错误?

Can anyone tell me how to fix this error?

推荐答案

您的模板正在被缓存.有几个变通方法.使用 Chrome 的开发工具在开发工具打开时禁用缓存,或者在您的应用程序中使用 $templateCache.remove().

Your template is being cached. There are a couple of work arounds. Either use Chrome's dev tools to disable cache when the dev tools is open, or use the $templateCache.remove() in your application.

app.run(function($rootScope, $templateCache) {
   $rootScope.$on('$viewContentLoaded', function() {
      $templateCache.removeAll();
   });
});

查找有关删除模板缓存的更多信息 这里.

Find more info on removing the template cache here.

这篇关于浏览器未检测到 AngularJS 中的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆