本節我們主要給大家介紹AngularJs如何調用Restful,實現數據的CRUD。
主要用到的技術:
后端:ASP.NET WebApi + SQLServer2008
前端:AngularJs,Bootstrap3
主要用到的開發工具
后端:VisualStudio2013 + SQLServer2008
前端:WebStorm8
1.創建后端項目AngularJs_WebApi
1.1建立空解決方案名稱AngularJs_WebApi
1.2 創建AngularJs_WebApi_Server服務端項目
1.3 選擇空的WebApi項目,並創建
1.4 新建控制器TestController類(用於測試)
1.5 編寫TestController.cs實現代碼
using System.Net.Http; using System.Web.Http; namespace AngularJs_WebApi_Server.Controllers { public class TestController : ApiController { public HttpResponseMessage Get() { return new HttpResponseMessage() { Content = new StringContent("我是通過Get請求的") }; } public HttpResponseMessage Post() { return new HttpResponseMessage() { Content = new StringContent("我是通過Post請求的") }; } public HttpResponseMessage Put() { return new HttpResponseMessage() { Content = new StringContent("我是通過Put請求的") }; } } }
1.6 通過Chrome應用程序REST Console測試剛才發布的服務(如果沒有可以到應用商店中去下載)
測試Get請求http://localhost:31194/api/test
請輸入我們的請求地址和請求方式
查看返回結果
測試Post請求http://localhost:31194/api/test
請輸入我們的請求地址和請求方式
查看返回結果
測試Put請求http://localhost:31194/api/test
請輸入我們的請求地址和請求方式
查看返回結果
(未完待續)














