標籤:turn get gen 曆史 出錯 post 請求方式 json 壓縮
1、建立服務的5種方式
//建立服務(1)
app.service("studentInfo",function(){
this.info = function(){
return{
UserId:"B13020505",
UserName:"小芳",
UserGender:"女",
UserAge:"19",
UserHobby:"寫字",
UserProfession:"漢語言文學"
}
}
})
//建立服務(2)
app.constant("studentInfoXW",{
UserId:"B13020506",
UserName:"小王",
UserGender:"男",
UserAge:"19",
UserHobby:"曆史",
UserProfession:"漢語言文學"
})
//建立服務(3)
app.value("studentInfoZS",{
UserId:"B13020507",
UserName:"張三",
UserGender:"男",
UserAge:"22",
UserHobby:"古玩",
UserProfession:"考古專業"
})
//建立服務(4)
app.factory("studentInfoLS",function(){
return{
UserId:"B13020508",
UserName:"李四",
UserGender:"男",
UserAge:"21",
UserHobby:"數學",
UserProfession:"數學專業"
}
})
//建立服務(5)
app.provider("studentInfoWYY",function(){
this.$get = function(){
return{
UserId:"B13020509",
UserName:"王語嫣",
UserGender:"女",
UserAge:"20",
UserHobby:"古典音樂",
UserProfession:"古典音樂專業"
}
}
})
2,angular get/post請求方式
// 1、http()
//$http({
// url: "student.json",
// method: "GET"
//})
//.success(function(data){
//console.log(data);
//$scope.StudentList = data.student;
//})
//.Error(function(data){
//console.log(data);
//console.log("出錯了!");
//})
//2、$http.get("student.json")
//.success(function(data){
//$scope.StudentList = data.student;
//})
//.error(function(data){
//console.log(data);
//console.log("出錯了!");
//})
3.$http.post("JSON/student.json")
.success(function(data){
$scope.StudentList = data.student;
})
.error(function(data){
console.log(data);
console.log("出錯了!");
})
3、行內式依賴注入的好處和優點
行內式依賴注入防止代碼壓縮將$scope換成-d導致代碼壓縮後出現不可預料的錯誤
angularjs相關知識