<script> function c(str) { console.log(str) } var app = angular.module("Myapp", ['ngRoute']) .config(['$locationProvider',function($locationProvider){ $locationProvider.html5Mode(false); $locationProvider.hashPrefix("!") }]) .config(function ($routeProvider) { $routeProvider .when('/', { templateUrl: 'views/main.html', controller: 'MainCtrl' }) .when('/about', { templateUrl: 'views/about.html', controller: 'AboutCtrl', }) .when('/action', { templateUrl: 'views/action.html', controller: 'ActionCtrl' }) .when('/contact:q', { templateUrl: 'views/contact.html', controller: 'ContactCtrl' }).when("/register", { templateUrl: 'views/register.html', controller: 'registerCtrl' }) .otherwise({ redirectTo: '/' }) }) .run(['$rootScope','$location',function ($rootScope,$location) { $rootScope.title = "网站的标题"; $rootScope.keywords = "网站的关键词"; $rootScope.description = "网站的描述"; //路由开始 $rootScope.$on('$routeChangeStart',function(evt, next, current){ }); //路由成功 $rootScope.$on('$routeChangeSuccess', function(evt, next, previous) { }); //路由错误 $rootScope.$on('$routeChangeError', function(current, previous, rejection) { c('$routeChangeError') c(current) c(previous) c(rejection) }); }]) .factory('myFactory', function(){ var service = {1:"a",2:"b",3:"c"}; return service; }) .directive('myDirective', function(){ return { template: '<button>Click me</button>' } }) .directive('ensureUnique', function ($http) { return { require: 'ngModel', link: function (scope, ele, attrs, cfg) { scope.$watch(attrs.ngModel, function () { $http({ method: 'POST', url: '/1.php', params: {filed: attrs.name, value: attrs.ngModel, value2: ele[0].value} }).success(function (data, status, headers, fg) { c(data); }).error(function (data, status, headers, fg) { alert('网络繁忙!'); }) }); } }; }) .controller('MainCtrl', function ($scope, $routeParams) { $scope.context = "Main页面标题"; $scope.add = function (num) { ++num; alert("num:" + num); }; $scope.name = {name: "a001", pwd: "a123456"}; }) .controller('AboutCtrl', function ($scope, $routeParams, $filter) { $scope.context = "关于我们"; $scope.other = "谢谢支持!"; // //$scope.name = $filter('lowercase'); $scope.unClock = function () { $scope.isDisabled = true; // alert('ok'); } $scope.myChange = function (d) { c(d); } $scope.submitForm = function (d) { c(d); } $scope.people = [ {name: "小A", city: "重庆"}, {name: "小b", city: "成都"}, {name: "小c", city: "武汉"}, {name: "小d", city: "广州"}, {name: "小e", city: "上海"} ]; $scope.fields = [ {isRequired: true, name: "user_name", placeholder: "请输入用户名", model1: "", msg: "请输入用户名"}, {isRequired: true, name: "user_pwd", placeholder: "请输入用户密码", model1: "", msg: "请输入用户密码"}, {isRequired: true, name: "email", placeholder: "请输入用户邮箱", model1: "", msg: "请输入用户邮箱"}, ] $scope.cx = "testcx" }).controller('ActionCtrl', function ($scope, $routeParams) { $scope.context = "Action测试页面"; }).controller('ContactCtrl', function ($scope, $routeParams) { $scope.context = "联系人"; }).controller("nowDae", function ($scope) { $scope.now = new Date(); $scope.do = function () { $.ajax({ url: '/1.php', type: 'post', dataType: 'json', async: false, data: {id: 10, user_name: 'a001', user_pwd: '123456'}, success: function (data) { c("data>>>>>"); c(data); } }) } }).controller("registerCtrl", function ($scope, $routeParams) { $scope.context = "用户注册"; $scope.showAgreement = function () { alert("用户协议..."); }; $scope.doreg = function () { alert('sdaf'); return false; } }) .filter('number2', function () { return function (input) { return "过滤过的:" + input; }; }).filter('email2', function () { return function (input) { if (input) { return "filter:" + input; } }; }) </script>
代码包下载:百度网盘
http://pan.baidu.com/s/1kUH1H0F