使用angular.forEach获取动态键匹配值

时间:2014-11-24 05:39:11

标签: angularjs

我有一个n输入json就像

     var err=  {"errors": 
                       {"username": ["Invalid login ID"],
                         "password": ["Invalid password"]
                }
               };

我必须使用angular.forEach获取用户名和密码的值。任何代码段吗?

1 个答案:

答案 0 :(得分:0)

angular.forEach(err['username'], function (username) {
    // here you will get all data which are part of username
    console.log(username); // You will see result as "Invalid login ID"
});

angular.forEach(err['password'], function (password) {
    // here you will get all data which are part of username
    console.log(password); // You will see result as "Invalid password"
});