html5 - angularJs为什么当我保存表单数据到数据库之时,在取不到与表单输入框绑定的model的值
大家讲道理
大家讲道理 2017-04-17 11:44:45
[HTML讨论组]

页面控制器定义如下:

appCtrls.controller('productAddCtrl', function ($scope,productService,localStorageService,$state) {
    $scope.productName = '';
    $scope.remark = '';
    $scope.$watch('productName',function(){

    })
    $scope.addNewProduct=function(){
        productService.addNewProduct($scope.productName,$scope.remark,localStorageService.getLocalStorage("user").userId);
        $state.go("tab.crm-productList");
    }
})

页面代码如下:

**<ion-view view-title="新产品">
    <ion-nav-buttons side="right">
        <a class="button button-clear" ng-click="addNewProduct()">完成</a>
    </ion-nav-buttons>
    <ion-nav-buttons side="left" >
        <a class="button button-clear" ui-sref="tab.crm-productList">取消</a>
    </ion-nav-buttons>
    <ion-content class="no-padding">
        <script id="templates/form-errors.html" type="text/ng-template">
            <p class="form-error" ng-message="required">这是必填项</p>
            <p class="form-error" ng-message="maxlength">This field is must be less than 50 characters</p>
        </script>
        <form name="addProductForm" novalidate>
        <p class="list">
            <p class="item item-pider">基本信息</p>
            <label class="item item-input" ng-class="{'has-error':addCustomerForm.name.$invalid}">
                <textarea type="text" name="name" placeholder="产品名称" required
                          ng-maxlength="1000" ng-model="productName">
                </textarea>
                <p>{{productName}}</p>
            </label>
            <p class="form-errors" ng-messages="addProductForm.name.$error"
                 ng-messages-include="templates/form-errors.html">
                <p class="form-error" ng-message="maxlength">请输入不超过1000位字符</p>
            </p>
            <p class="item item-pider">其他信息</p>
            <label class="item item-input" ng-class="{'has-error':addCustomerForm.remark.$invalid}">
                <textarea type="text" name="remark" placeholder="备注"
                          ng-maxlength="5000" ng-model="remark">
                </textarea>
                <p>{{remark}}</p>
            </label>
            <p class="form-errors" ng-messages="addProductForm.remark.$error"
                 ng-messages-include="templates/form-errors.html">
                <p class="form-error" ng-message="maxlength">请输入不超过5000位字符</p>
            </p>
        </p>
            </form>
    </ion-content>
</ion-view>**

执行addNewProduct该方法之时,不管在页面输入什么,点击完成后$scope.productName,$scope.remark都为空

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(1)
PHPz

addNewProduct这个方法执行完成之后路由不是跳转了么,跳转的话controller就重新加载了,所以model里面的值就为空了

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号