angularjs相關知識

來源:互聯網
上載者:User

標籤: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相關知識

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.