Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 第三组 张国梁/笔记/刘单/angular.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
##路由Route - 1 angular-route是angular自带的路由模块 - 2 安装:npm install angular-route - 3 依赖模块 让当前木块依赖于ngRoute 先执行appMoudle,在执行ngRoute var app =angular.module('appMoudle',['ngRoute']); //appModule.controller多模块之间的依赖 var app =angular.module('appMoudle',['ngRoute','appModule.controller']); - 4 配置路由 路由:根据不同路径返回不同内容 app.config(function($routeProvider){ //$routeProvider 是服务中的this 获取路由参数 }).then([url],[object])//增加路由 例子: app.config(function ($routeProvider) { $routeProvider.when('/home',{ template:'<div>首页 {{title}}</div>', controller: function ($scope) {//控制器 $scope.title = 'hello ' } }).when('/user',{ template:'<div>用户</div>', controller: function ($scope) { $scope.title = 'hello ' } }).when('/contact',{ template:'<div>zfpx</div>', controller: function ($scope) { $scope.title = 'hello ' } }).when('/settings',{ template:'<div>设置页面</div>', }).otherwise('/home'); }) - 5 创建路由链接 html: <a href="#/home">首页</a> <a href="#/user">用户管理</a> <a href="#/contact">联系</a> <a href="#/settings">设置</a> <!--将页面的内容编辑进去--> <div ng-view></div> - 6 监控路由变化 app.run(function ($rootScope,$location) { //$location 路由提供的服务 $rootScope.flag = false; $rootScope.$on('$routeChangeStart', function (event,toState,fromState) { if(toState.$$route.originalPath=='/settings'){ if(!$rootScope.flag){ $location.path('user');//服务里里跳转url alert('没有权限自动跳转到用户页面') event.preventDefault(); } } }) }); 注意: $location.path(url) 跳转到当前页面 $location.absurl() 返回到当前页面的url - 7 路由里面的参数配置 var app=angular.module('appModule',['ngResource','ngRoute','appModule.controller']); //路由基于配置 app.config(function ($routeProvider) { $routeProvider.when('/detail/:id',{//表示id要有,但是随即的 templateUrl:'tmpl/detail.html', controller:'detailCtrl' }).otherwise('/'); }) //将方法提取出来 app.factory('Books',function($resource){ //url:路径; null:默认值;object:增加的方法 return $resource([url],null.[object]) }) 例子: app.factory('User',['$resource',function ($resource) { return $resource('/user/:bid',null,{///id:id可有可无 updata:{method:'PUT'}//我们自己增加的方法 }) }]) app.controller('myCtrl',function ($scope,$http,User) {//控制器是调用方法的使用 User.query();//获取所有用户 GET /user // User.get({bid:2})//获取一个通过id获取 GET /user/2 User.remove({bid:3})//删除 第三个 这里的id是根据前面获取的id来的 }) ##readBook/writeBook 读取/写入 - 读取json中的内容,为json格式 function readBook(callback){ fs.readFile('./book.json','utf8',function(err,data){ if(err || data == ''){ data='[]'; } data=JSON.parse(data); callback(data); }) } - 将对象类型的数据 写入到json中 functon writeBook(data,callback){ fs.writeFile('./book.json',JSON.stringiFy(data,callback)) }
Expand Down
1 change: 1 addition & 0 deletions 第三组 张国梁/笔记/刘单/note.md

Large diffs are not rendered by default.

Loading