本文介绍了WEBMETOD中的ANGULAR和SQL C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友
我想问一下如何使用webmetod和ajax使用angularjs返回数据
我见过人们这样做它在asp - MVC模式中。但我想用asp正常做
这段代码对我不起作用:
MyPage
Hello friends
I wanted to ask how I can return data with angularjs using webmetod and ajax
I've seen people do it in asp - MVC pattern. but I want to do it with asp normal
This code does not work for me :
MyPage
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static List<Student> GetStudent()
{
List<Student> lstStudents = new List<Student>()
MyApp
MyApp
var app = angular.module('app', ['ngResource']);
app.controller('studentsCtrl', function ($scope, student) {
$scope.student = student;
});
app.value('pageMethods', PageMethods);
app.factory('student', function (pageMethods, $rootScope) {
var result = [];
pageMethods.GetStudent(function (data) {
data.forEach(function (item) {
result.push({ id: item.id, name: item.name});
});
$rootScope.$apply();
});
return result;
})
推荐答案
这篇关于WEBMETOD中的ANGULAR和SQL C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!