Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ng dirty未按预期工作_Javascript_Jquery_Angularjs - Fatal编程技术网

Javascript ng dirty未按预期工作

Javascript ng dirty未按预期工作,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我很难理解为什么我的元素在更新模型后显示ng dirty 我有一个需要在UI上呈现的桥的集合。在每次单击选项卡时,我都会更改索引并呈现数据 如果我的第一个选项卡数据已更改并移动到第二个选项卡,为什么第二个选项卡上的输入元素仍然脏。(函数-$scope.changeIndex) 执行计算后,模型会更新,但输入元素仍然脏 用户界面 从 ng dirty在表单脏时设置 这是检查表单本身是否以任何方式进行了交互。它不关心底层对象绑定是什么。这是预期的行为,因为您使用的是相同的表单,但在幕后更改了ng模型

我很难理解为什么我的元素在更新模型后显示
ng dirty

我有一个需要在UI上呈现的桥的集合。在每次单击选项卡时,我都会更改索引并呈现数据

  • 如果我的第一个选项卡数据已更改并移动到第二个选项卡,为什么第二个选项卡上的输入元素仍然脏。(函数-
    $scope.changeIndex

  • 执行计算后,模型会更新,但输入元素仍然脏

  • 用户界面

    ng dirty
    在表单脏时设置


    这是检查表单本身是否以任何方式进行了交互。它不关心底层对象绑定是什么。这是预期的行为,因为您使用的是相同的表单,但在幕后更改了
    ng模型。

    不知道这是否是问题所在,但行
    $scope.$setPristine没有做任何事情。它应该是:
    $scope.$setPristine()

    那么在后台更新模型后,如何删除ng dirty。您可以将表单本身设置为原始状态。这类似于
    $scope.nameOfForm.$setPristine()
    或者您可以重做选项卡逻辑以依赖除
    ng dirty
    之外的其他内容(可能附加另一个您手动跟踪的属性)。您好,jlew,对不起,我以为我删除了该设置Pristine,我只是想看看它是否更改。编辑代码。
    <td style="padding:10px;text-align:center">
        <label>Length:</label>
        <input type="text" class="currencyLabel-editable" ng-model="bridgeModel.bridges[currentIndex].length" />
    </td>
    
    <td style="padding:10px;text-align:center">
        <label>Width:</label>
        <input type="text" class="currencyLabel-editable" ng-model="bridgeModel.bridges[currentIndex].width" />
    </td>
    
    <td style="padding:10px;text-align:center">
        <label> Skew:</label>
        <input type="text" class="currencyLabel-editable" ng-model="bridgeModel.bridges[currentIndex].skew" />
    </td>
    
    (function () {
    
    
    var bridgeCtrl = function ($scope, $bootstrapBridgeData, $crudService,$log) {
    
    
        $scope.bridgeModel = $bootstrapBridgeData.bridgeModel;
    
    
        var onCalculateComplete = function (data) {
            $scope.bridgeModel.bridges[$scope.currentIndex] = angular.copy(angular.fromJson(data));
    
        }
    
        var onCalculateError = function (reason){
            $scope.error = "Unable to perform calculation";
            $log.error(reason);
        }
    
        var onError = function (reason) {
            $scope.error = "Unable to fetch data";
        }
    
    
    
        //function to null the values which needs to be re-computed
        var removeCalculatedValues = function () {
    
    
            $scope.bridgeModel.bridges[$scope.currentIndex].foundation_PreBoringCalculated = null;
            $scope.bridgeModel.bridges[$scope.currentIndex].foundation_DrilledShaftsCalculated = null;
    
        }
    
        //function to compute the bridge values
        $scope.calculate = function (url) {
    
            if (!preValidation()) {
                return false;
            }
    
            removeCalculatedValues();
    
            $crudService.postAndGetData(url, $scope.bridgeModel.bridges[$scope.currentIndex])
                         .then(onCalculateComplete, onCalculateError)
    
    
        }
    
        //function to select the bridge and change the index of the bridge
        $scope.changeIndex = function (bridgeName,index) {
             $scope.selectedBridge = bridgeName;
             $scope.currentIndex = index;           
        }
    
        $scope.save = function (index, url) {
    
            $scope.currentIndex = index;
            crudService.postAndGetData(url, $scope.bridges[index])
                       .then(onUserComplete, onError);
    
        }
    
        //$scope.enableSave = function isFormDirty() {
    
        //    if ($(".ng-dirty").length) {
        //        return false;
        //    }
        //    else { return true; }
        //}
    
        //Behaviour Changes
    
    
        //function which changes the css 
        $scope.isBridgeSelected = function (bridge) {
            return $scope.selectedBridge === bridge;
        }
    
        var preValidation = function () {
    
            if ($(".ng-invalid").length) {
                alert("Please correct the errors.")
                return false;
            }
            else { return true;}
        }
    
    
    
    }
    
    
    //Get the module and add a controller to it
    var module = angular.module("bridgeModule");
    module.controller("bridgeCtrl", bridgeCtrl);
    
    }());