angularjs - 显示数据时出错 - 范围 - AngularJS
问题描述
我在使用 AngularJS 显示数据时遇到问题。
所以我的应用程序基于 AngularJS 和 CodeIgniter 3。
我在 CodeIgniter 中创建了一个以表单形式编写的验证,一切正常。
public function create()
{
$this->form_validation->set_error_delimiters('','');
$this->form_validation->set_rules( 'login' , 'Imię' , 'required|min_length[3]' );
$this->form_validation->set_rules( 'email' , 'Email' , 'required|valid_email|is_unique[users.email]' );
$this->form_validation->set_rules( 'password' , 'Hasło' , 'required|matches[passconf]' );
$this->form_validation->set_rules( 'passconf' , 'Powtórz hasło' , 'required|matches[password]' );
if ( $this->form_validation->run())
{
$user = $this->input->post('user');
unset($user['passconf']);
$user['password'] = crypt($user['password'], config_item('encryption_key'));
$this->Users_model->create($user);
}
else
{
$errors['login'] = form_error( 'login' );
$errors['email'] = form_error( 'email' );
$errors['password'] = form_error( 'password' );
$errors['passconf'] = form_error( 'passconf' );
echo '{"records":' . json_encode( $errors ) . '}';
}
}
在 AngularJS 方面,我希望出现错误。
controllersAdmin.controller('userCreate', function( $scope, $http, $timeout ){
$scope.user = {};
$scope.user.role = 'user';
$scope.createUser = function( user ){
$http({
method: 'POST', url: 'api/admin/users/create/' ,
data: {
user : user,
login : user.login,
email : user.email,
password : user.password,
passconf : user.passconf
}}
).then(function ( errors ){
if ( errors )
{
$scope.errors = errors;
}
else
{
$scope.success = true;
$timeout(function(){
$scope.success = false;
$scope.user = {};
} , 3000 );
}
},function (error){
console.log('Blad we wczytywaniu danych');
});
}
});
我建立$scope.errors = errors;
当我用{{errors}}
- 显示它时,显示数据。
{"data":{"records":{"login":"Pole Imię jest wymagane.","email":"Pole Email jest wymagane.","password":"Pole Hasło jest wymagane.","passconf":"Pole Powtórz hasło jest wymagane."}},"status":200,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"api/admin/users/create/","data":{"user":{"role":"user"}},"headers":{"Accept":"application/json, text/plain, */*","Content-Type":"application/json;charset=utf-8"}},"statusText":"OK","xhrStatus":"complete"}
但是,当我给时{{errors.login}}
,数据不显示。我能指望一点帮助吗?
解决方案
有你的问题。登录不是错误对象的属性,而是子属性。它应该是errors.data.records.login。
推荐阅读
- c# - C#While循环没有意外输出任何东西
- java - 我们可以在 Ubuntu 上使用 openJDK10 进行离子开发吗?
- javascript - Braintree 沙盒错误中的 PayPal 集成:PAYPAL_SANDBOX_ACCOUNT_NOT_LINKED
- python - 如何将列表的每个元素写入 csv 文件中的单独字段?
- cordova - 类型“typeof auth”上不存在属性 verifyPhoneNumber
- c# - 将 SQL 查询限制为 SELECT 操作 ASP.net C#
- web - Service Worker 缓存的资产的生命周期是多久?
- android - Graphview 是否允许在 x 轴或 y 轴上设置刻度?
- angularjs - SheetJS xlsx 单元格样式
- pytest - 我如何在 Pycharm 中使用 pytest-html?