AngularJS将一个字段值设置为对象内的另一个字段

时间:2017-08-23 13:43:47

标签: javascript angularjs

也许是愚蠢的问题,但

$scope.registration = {
        email: "",
        userName: "",
        password: "",
        confirmPassword: "",
        firstName: "DummyFirstName",
        lastName: "DummyLastName"
    };

我希望userNameemail相同。

我试过了:

$scope.registration = {
        email: "",
        userName: email,
        password: "",
        confirmPassword: "",
        firstName: "DummyFirstName",
        lastName: "DummyLastName"
    };

但是我得到了不存在的错误。

1 个答案:

答案 0 :(得分:1)

你可以这样做:

$scope.registration = {
    email: "",
    password: "",
    confirmPassword: "",
    firstName: "DummyFirstName",
    lastName: "DummyLastName"
};
$scope.registration.userName = $scope.registration.email;