发表于: 2017-04-17 23:45:13
2 1118
今天完成的事情-收获:
今天试着做起来了任务6的路由
先尝试这实现一些小功能DOM
htm部分
<div class="content">
<ul ng-app="transmit" class="list">
<li><a href="#/">学员列表</a> </li>
<li><a href="#/computers">新增学员</a> </li>
<li><a href="#/">个人信息</a> </li>
</ul>
<div ng-view class="manage">
<h2></h2>
</div>
</div>
Js部分
angular.module("transmit"["ngRoute"])
.config(['$tran',function($tran) {
$tran
.when('/',{template:'这是首页页面'});
.when('/computers',{template:'这是电脑分类页面'})
.otherwise({redirectTo:'/'});
}])
看到了这样的写法我的思路顿时明朗了起来。。原来ANGULAR有它本身的异步啊?
异步请求之$http对象。
AngularJS 提供了一个类似jquery的$.ajax的对象,用于异步请求。
在AngularJS中对异步操作是推崇至极的,所以$http的操作都是异步的不像jquery.ajax里还提供了async参数。
1 2 3 4 5 6 7 | $http({method : 'POST',params : { id:123}, data:{name:'john',age:27}, url : "/mypath"}).success(function(response, status, headers, config){//do anything what you want;}).error(function(response, status, headers, config){//do anything what you want;}); |
如果你是POST请求,params里的数据会帮你拼到url后面,data里的数据会放到请求体中。
但是一直报错,也许是我引入错了么?(这里的问题下面说)
明天计划的事情:完善任务6
遇到的问题:
问题来了
路径配置了 :http://localhost/JS-6/welcome.html 还是会出现这样的错误。
也许是我哪里写错了?
问了老哥,发现我语法错的离谱啊
改成了这样
angular.module('transmit',['ngRoute'])
.config(['$routeProvider', function($routeProvider){
$routeProvider
.when('/',{template:'这是首页页面'})
.when('/computers',{template:'这是电脑分类页面'})
.when('/printers',{template:'这是打印机页面'})
.otherwise({redirectTo:'/'});
}]);
评论