角JS CRUD更新不刷新 [英] Angular JS CRUD update not refreshing

查看:222
本文介绍了角JS CRUD更新不刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的看法是没有得到体现后,更新/删除/创建

我的列表页面EmpList。我的更新页面EmpDetail。

下面是我的控制器

  $ scope.UpdateEmp =功能(){
            VAR EMPL = $ scope.Employee;
            empFactory.empUpdate.update({的EmpID:$ routeParams.EmpID,empval:EMPL});
            $ location.path('/ EmpList');        };

下面是我的服务

  VAR资源= {
        empUpdate:
            $资源(../../公司雇员/ PutEmployee /:的EmpID',{的EmpID:@EmpID',empval:@empl'},{更新:{方法:把',IsArray的:真正}})
    }    返回的资源;

下面是我的MVC控制器

  [HttpPut]
        公共JsonResult PutEmployee(INT ID,员工empval)
        {
            empval.EmpID = ID;
            INT指数= emp.GetEmployees()FindIndex(I => i.EmpID == empval.EmpID)。
            emp.GetEmployees()RemoveAt移除(索引)。
            。emp.GetEmployees()添加(empval);
            返回JSON(emp.GetEmployees(),JsonRequestBehavior.AllowGet);
        }

MVC控制器获取调用和数据得到正确更新,但它没有得到体现在主页

请注意:在Emplist.html,我有控制器映射在那里我米做的查询部分以反映更改。该URL不是在所有重定向到EmpList。

  $ scope.Employees = empFactories.query(函数(){
    的console.log($ scope.Employees);
});


解决方案

您要发送的数据,但不能使用回复:

 回复= empFactory.empUpdate.update({的EmpID:$ routeParams.EmpID,empval:EMPL});

现在您可将回复你的 $范围

My view is not getting reflected after the update/Delete/Create

My List page is EmpList. My update page is EmpDetail.

Here is my controller

   $scope.UpdateEmp = function () {
            var empl=$scope.Employee;
            empFactory.empUpdate.update({ EmpID: $routeParams.EmpID, empval: empl });
            $location.path('/EmpList');

        };

Here is my Service

 var resource = {
        empUpdate:
            $resource('../../Employee/PutEmployee/:EmpID', { EmpID: '@EmpID', empval: '@empl' }, { update: { method: 'PUT', isArray: true } })
    }

    return resource;

Here is my MVC controller

 [HttpPut]
        public JsonResult PutEmployee(int id, Employee empval)
        {
            empval.EmpID = id;
            int index = emp.GetEmployees().FindIndex(i => i.EmpID == empval.EmpID);
            emp.GetEmployees().RemoveAt(index);
            emp.GetEmployees().Add(empval);
            return Json(emp.GetEmployees(), JsonRequestBehavior.AllowGet);
        }

MVC controller is getting called and the data is getting updated correctly, but it's not getting reflected in the main page

Note: In Emplist.html, I have the controller mapped where I m doing the query part to reflect the changes. The URL is not redirected to EmpList at all.

$scope.Employees = empFactories.query(function () {
    console.log($scope.Employees);
});

解决方案

You're sending the data but not using the reply:

reply = empFactory.empUpdate.update({ EmpID: $routeParams.EmpID, empval: empl });

Now you can assign the reply to your $scope

这篇关于角JS CRUD更新不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆