1. 程式人生 > >angularJs常用事件

angularJs常用事件

ui-router禁用快取

 //配置路由
app.config(function ($stateProvider, $urlRouterProvider, $httpProvider) {
    //禁止快取
    if (!$httpProvider.defaults.headers.get) {
        $httpProvider.defaults.headers.get = {};
    }
    // Enables Request.IsAjaxRequest() in ASP.NET MVC
    $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';

    // Disable IE ajax request caching
    $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
    $httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
    $httpProvider.defaults.headers.get['If-Modified-Since'] = '0';
   
    $urlRouterProvider.otherwise("/order_1"); //預設首頁
    $stateProvider.state("order_1", { url: "/order_1", templateUrl: "/OrderInfo?orderState=0", controller: "OrderAllController" })
});

//清除快取
app.run(function ($rootScope, $templateCache) {
    $rootScope.$on('$viewContentLoaded', function () {        
        $templateCache.removeAll();
    });
});

ui-router傳參

ui-sref="workbench({type:1})"
//接收引數
app.controller('WorkbenchCtrl', function ($stateParams, $scope) {
	console.log($stateParams.type);
});
//templateUrl傳參
templateUrl: function($stateParams){return 'project/'+$stateParams.id;},

ng-repeat含有重複項在後邊加 track by $index

ng-repeat="data in postNum track by $index"