AngularJs常用$http

常用对数据库里数据的增删改查

angular.module("app", [])
    .controller("MyCtrl", function ($scope, $http) {
        $scope.Sname = "";
        $scope.se = {};

        $http.get("odata/Use").then(function (data) {  //查询Use里的所有数据
            $scope.list = data.data.value;
        })

        $scope.remove = function (id) {  //删除Use里单独一条数据
            $http.delete("odata/Use(" + id + ")")
                .then(function () {
                    window.location = location
                    alert("删除成功")
                })
        }
        $scope.insert = function (s) { //增加一条数据
            $scope.name = { "name": s } 
            $http.post("odata/Use", $scope.name)
                .then(function () {
                    window.location = location
                    alert("添加成功")
                })
        }
        $scope.update = function () { //修改一条数据
            $http.put("odata/Use(" + $scope.se.id + ")", $scope.se)
                .then(function () {
                    window.location = location
                    alert("修改成功!")
                })
        }
        $scope.u = function (st) { //把要修改的数据给$scope.se
            $scope.se = st;
        }

    })

你可能感兴趣的:(初步学习)