不能设置选择采用了棱角分明的js code的选择吗? [英] cannot set option of the select using angular js code?

查看:109
本文介绍了不能设置选择采用了棱角分明的js code的选择吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面的HTML

<div class="form-group ">
    <label class="col-sm-3 control-label">Role</label>
    <div class=" col-sm-8">
        <select type="text" id="role" name="role" ng-model="role" class="form-control" required>
            <option value="">Select Role</option>
            <option ng-repeat="rol in rolelist" value="{{rol.id}}">{{rol.title}}</option>
        </select>
        <p class="ng-invalid" ng-show="addForm.role.$error.required">Role need to selected</p>
    </div>
</div>

我要设置角色值动态点击数据集进行更新的目的和设置的DOM元素(控制)的价值;这样做,我还不能跟上内部控制器code

I want to set value of role dynamically clicking data-sets for the purpose of update and setting value of dom element (control); to do so i had following code inside controller

$scope.data_set=function(id)
        {
            BlockUi();
            url=siteurl+'/admin/'+module+'/get-info';

                $http({
                    url     :   url,
                    method  :   "POST",
                    data    :   {"id":id}

                }).then(function(responseText){
                    data=responseText.data;
                    $scope.first_name=data.first_name;
                    $scope.user_id=data.id;
                    $scope.last_name=data.last_name;
                    $scope.user_name=data.user_name;
                    $scope.role=data.role;

                    $scope.email=data.email;
                    $scope.contact_number=data.contact;
                    $scope.image_file=data.image;
                    $scope.status=data.status;

                    UnblockUi();
                },function(error){
                    UnblockUi();
                    UnknownError();
                    alert(JSON.stringify(error));
                });
        }

以上code工作,但所有的角色模型;我看着并遵守的其他问题的解决方案,但我没有工作?

above code works for all but role model; I watched and follow other question's solutions but did not work for me?

这code后删除NG要求的错误;

and ng-required error is removed after this code;

推荐答案

感谢各位的努力
其实我误入每一个地方,但解决方法很简单;其问题的数据类型;实际选择:角色模型包含字符串数据类型,并始终;我设置整数数据类型为榜样,这是错误的;我JSON数据的数据类型转换为字符串,并设置角色模型的价值正常工作。

thanks for effort of everybody Actually i strayed every where, but solution is simple ; its problem with datatype; actually select: role model contains string datatype and always ; i am setting the integer datatype to role model which is wrong; i convert the datatype of the data of json to string and set the value of role model works fine.

这篇关于不能设置选择采用了棱角分明的js code的选择吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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