要胀爆的Angular1.0

尝试从http请求上遏制缓存:

http://blog.csdn.net/u010039979/article/details/54376856

     if (!$httpProvider.defaults.headers.get) {
            $httpProvider.defaults.headers.get = {};
        }
//或者可以写成
$httpProvider.defaults.headers.get = $httpProvider.defaults.headers.get || {};

     $httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon, 26 Jul 1997 05:00:00 GMT'; $httpProvider.defaults.headers.common[
'X-Requested-with'] = 'XMLHttpRequest'; $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

想要适当缓存:http://www.cnblogs.com/jiuyuehe/p/5238622.html

(function () {

  'use strict';

  var AppController = function ($scope, $rootScope, TranslateService) {
    // Set page title on each page
    this.listener = $scope.$on('$routeChangeSuccess', function (e, nextRoute) {
      if (nextRoute.$$route && angular.isDefined(nextRoute.$$route.pageTitle)) {
        $scope.pageTitle = nextRoute.$$route.pageTitle + ' | Bosch Warranty Process';
      }
    });

    // when account data changes, set language that needs to be used
    this.watcher = $rootScope.$watch('account', function () {
      if (typeof $rootScope.account != 'undefined' && typeof $rootScope.account.language != 'undefined') {
        TranslateService.changeLanguage($rootScope.account.language);
      } else {
        TranslateService.setDefaultLanguage();
      }
    });

    $scope.$on("$destroy",function(){
       AppController.listener(); 
    AppController.listener = null;
    $scope.$destroy();
}); $rootScope.$on("$destroy",function(){ AppController.watcher();
    AppController.watcher = null;
    $rootScope.$destroy();
    $rootScope.$digest();
}); }; AppController.$inject = ['$scope', '$rootScope', 'TranslateService']; angular .module('warrantyProcessApp') .controller('AppController', AppController); })();

清除rooteScope:

-    it('should ignore remove on root', inject(function($rootScope) {
+    it('should broadcast $destroy on rootScope', inject(function($rootScope) {
+      var spy = spyOn(angular, 'noop');
+      $rootScope.$on('$destroy', angular.noop);
       $rootScope.$destroy();
       $rootScope.$digest();
       expect(log).toEqual('123');
+      expect(spy).toHaveBeenCalled();
+      expect($rootScope.$$destroyed).toBe(true);
     }));

https://github.com/angular/angular.js/commit/d802ed1b3680cfc1751777fac465b92ee29944dc

关于$digest();

理解Angular中的$apply()以及$digest()

清除scope:

  var offDestroy = $scope.$on('$destroy', function() {
    scope.$destroy();
  });
  scope.$on('$destroy', offDestroy);

清除scope监听的事件http://liyunpeng.iteye.com/blog/2257154

另外闭包什么的就麻烦了:

http://www.cnblogs.com/carekee/articles/1733847.html

语法错集锦:

Error: [$compile:ctreq] Controller 'ngModel', required by directive 'ngChange', can't be found!

提示:有ng-change的标签却没有ng-module

解决方法:在input上加上ng-model属性,例如你要获取input里面的值,在controller中定义: $scope.aValue = '', 然后模板中 <input ng-model='aValue' ng-change='mychange()' />

原文地址:https://www.cnblogs.com/haimingpro/p/6429224.html