更新屏幕上不起作用的$ scope值

时间:2016-06-23 23:52:17

标签: html angularjs asp.net-mvc

我的ASP.Net MVC / Angular应用程序问题非常烦人。

所以,我有div显示员工的名字和姓氏:

<div ng-repeat="x in supervisors | limitTo:1" ng-show="!svElements" class="item_list">{{x.supervisorfName}} {{x.supervisorlName}}</div>
默认情况下,

svElements在范围内定义为falls,因此div可见。

然后我有一个链接,该链接将隐藏名称并显示一个列表框select tag,它还显示名称列表(连接的名字和姓氏)。

<div ng-show="!svElements"><a href="javascript:void(0)" ng-click="toggle()">Edit</a></div>

当我点击链接时,它只会调用一个toggle函数来生成$scope.svElement = !$scope.svElement ...换句话说,它会隐藏div并显示下面的列表:

<div ng-show="svElements">
<select ng-model='svFullName' ng-selected='svFullName'>
    <option ng-repeat="z in supervisorsList">{{z.supervisorfName + " " + z.supervisorlName}}</option>
</select>
<a href="javascript:void(0)" ng-click="updateUserSupervisor(x, z)">Save</a>                                                                                                

在我的Angular控制器中,我首先带上主管的名字:

$http.get('/Home/GetSupervisor')
    .then(function (response) {
        $scope.supervisors = response.data;
        $scope.svFullName = response.data[0].supervisorfName + " " + response.data[0].supervisorlName;
    })
    .catch(function (e) {
        console.log("error", e);
        throw e;
    })
    .finally(function () {
        console.log("This finally block");
    });

以上代码调用以下MVC方法:

public JsonResult GetSupervisor()
    {
        User userData = (User)Session["user"];            
        var db = new scaleDBEntities();
        var superid = db.Users.Where(u => u.Id == userData.Id)
                  .Select(u => u.usrSupervisor)
                  .FirstOrDefault();
        int superid_int = int.Parse(superid.ToString());
        return this.Json((from userObj in db.Users
                          where userObj.Id.Equals(superid_int)
                          select new
                          {
                              supervisorId = userObj.Id,
                              supervisorfName = userObj.usrFirstName,
                              supervisorlName = userObj.usrLastName
                          })
                          , JsonRequestBehavior.AllowGet
                        );            
    }

然后,从我的角度控制器中我带上了监督员名单

$http.get('/Home/GetSupervisorsList')
    .then(function (response) {
        $scope.supervisorsList = response.data;
    })
    .catch(function (e) {
        console.log("error", e);
        throw e;
    })
    .finally(function () {
        console.log("This finally block");
    });

同样,上面的代码调用了下面的MVC方法:

public JsonResult GetSupervisorsList()
    {
        User userData = (User)Session["user"];
        var db = new scaleDBEntities();
        return this.Json((from userObj in db.Users
                          where userObj.Id != userData.Id
                          select new
                          {
                              supervisorId = userObj.Id,
                              supervisorfName = userObj.usrFirstName,
                              supervisorlName = userObj.usrLastName
                          })
                          , JsonRequestBehavior.AllowGet
                        );
    }

当我点击“保存”以更新主管时,下面的角度代码可以工作:

$scope.updateUserSupervisor = function (x, z) {
    $http.post('/Home/UpdateUserSupervisor', { svId: $scope.selectedSVID })
        .then(function (response) {
            $scope.users = response.data;
            x.supervisorfName = z.supervisorfName;
            x.supervisorlName = z.supervisorlName;
        })
    .catch(function (e) {
        console.log("error", e);
        throw e;
    })
    .finally(function () {
        console.log("This finally block");
    });
    $scope.svElements = !$scope.svElements;
}

我的问题是:为什么在更新主管后,我无法重置/更新顶部包含名字和姓氏的div值?

一切正常,但是当我保存时,它应该更新显示的名称而不刷新页面?

0 个答案:

没有答案