双向绑定在角度js中不起作用 [英] Two way binding is not working in angular js

查看:102
本文介绍了双向绑定在角度js中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单来向数据库提交数据。第一次加载页面时它工作正常。但是当我们点击提交第二个谷的第一次提交后,然后控制台说错了请求。这是因为$ scope中的所有值都为null。



当我逐步调试js然后再次工作时。



如何解决这个问题。



 $ scope.Save =  function (){

var MainMenuRecord =
{
MainMenuId:$ scope.Form。 MainMenuId,
MainMenu:$ scope.Form.MainMenu,
PageTitle:$ scope.Form.PageTitle,
PageUrl:$ scope.Form.PageUrl,
MainMenuOrder:$ scope。 Form.MainMenuOrder,
UpperText:$ scope.Form.UpperText,
LowerText:$ scope.Form.LowerText,
UpperStatus:$ scope.Form.UpperStatus,
LowerStatus:$ scope.Form.LowerStatus,
HomePanelStatus:$ scope.Form.HomePanelStatus,
PageId:$ scope.Form .PageId
};
var promisePost = MainMenuService.post(MainMenuRecord);
promisePost.then( function (pl){
alert(' Mainmenu' + pl.statusText + ' Successfully。');
Clear();
$ scope.Form.pageNumber = 1 ;
LoadRecord();
console .log(pl.data);

}, function (错误) ){
console .log( Err + err.Message);
});

}





和服务是





 app.service('  MainMenuService' function ($ http){

// 创建新记录
.post = function (tblmainmenu){
var request = $ http({
method: post
url: / api / MainMenuAPI
data:tblmainmenu
});
return request;
}
}

解决方案

范围。



当id一步一步地推动js再次工作。



如何解决这个问题。



 


scope.Save = function (){

var MainMenuRecord =
{
MainMenuId:


scope.Form.MainMenuId,
MainMenu:

I have a form to submit data to database. first time when page is loaded it is working fine. but after first submit when we click submit for second vale then console said bad request. this is because all the value are null in $scope.

when i debugging js step by step then again its working.

How to fix this issue.

$scope.Save = function () {
        
        var MainMenuRecord =
            {
                MainMenuId: $scope.Form.MainMenuId,
                MainMenu: $scope.Form.MainMenu,
                PageTitle: $scope.Form.PageTitle,
                PageUrl: $scope.Form.PageUrl,
                MainMenuOrder: $scope.Form.MainMenuOrder,
                UpperText: $scope.Form.UpperText,
                LowerText: $scope.Form.LowerText,
                UpperStatus: $scope.Form.UpperStatus,
                LowerStatus: $scope.Form.LowerStatus,
                HomePanelStatus: $scope.Form.HomePanelStatus,
                PageId: $scope.Form.PageId
            };
        var promisePost = MainMenuService.post(MainMenuRecord);
        promisePost.then(function (pl) {
            alert('Mainmenu ' + pl.statusText + ' Successfully.');
            Clear();
            $scope.Form.pageNumber = 1;
            LoadRecord();
            console.log(pl.data);
           
        }, function (err) {
            console.log("Err" + err.Message);
        });
       
    }



and service is


app.service('MainMenuService', function ($http) {

    //create new record
    this.post = function (tblmainmenu) {
        var request = $http({
            method: "post",
            url: "/api/MainMenuAPI",
            data: tblmainmenu
        });
        return request;
    }
}

解决方案

scope.

when i debugging js step by step then again its working.

How to fix this issue.


scope.Save = function () { var MainMenuRecord = { MainMenuId:


scope.Form.MainMenuId, MainMenu:


这篇关于双向绑定在角度js中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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