在使用json数据动态填充的下拉列表中选择默认值。
曾尝试使用regCtrl.screeningTypeList [0],这没有帮助。
<select ng-init="regCtrl.user.screeningType.screeningTypeId=regCtrl.screeningTypeList[0]" ng-model="regCtrl.user.screeningType.screeningTypeId" ng-change="regCtrl.getType(regCtrl.user.screeningType.screeningTypeId)"
ng-options="sctype.screeningTypeId as sctype.screeningType for sctype in regCtrl.screeningTypeList"
class="form-control field-size ng-pristine ng-invalid ng-invalid-required ng-valid-maxlength ng-touched" name="screeningType"
id="screeningType" required >
<!-- <option value="">--SELECT--</option> -->
<!-- <option value="{{sctype.screeningTypeId}}">{{sctype.screeningType}}</option> -->
</select>
这是用于返回json数据的角度js代码。
function getScreeningTypeList(){
$http({
method: 'GET',
url: 'master/getAllScreeningTypeMast'
}).success(function(response){
vm.screeningTypeList=response.result;
}).error(function(resp){
});
}
控制器其他相关代码,在开头定义,此值分配给vm。
RegistrationController.$inject = ['$http','LookupService','$filter'];
function RegistrationController($http,LookupService,$filter){
var vm = this;
}
答案 0 :(得分:2)
pr($this->Auth->user()); in your login action in UsersController.
删除元素上的ng-init,
答案 1 :(得分:1)
您可以尝试在http请求后为模型提供值。
function getScreeningTypeList(){
$http({
method: 'GET',
url: 'master/getAllScreeningTypeMast'
}).success(function(response){
vm.screeningTypeList=response.result;
$scope.regCtrl.user.screeningType.screeningTypeId=vm.screeningTypeList[0]; // in your case i think you have to replace $scope by vm
}).error(function(resp){
});
}
或者尝试在ng-init中添加一个函数
Function nginitSelect(){
$scope.regCtrl.user.screeningType.screeningTypeId= $scope.regCtrl.screeningTypeList[0]; // in your case i think you have to replace $scope by vm
}