I am creating an object as following in my Angular Controller.
However, I need to make Password and Confirm Password properties conditionally.
I am currently doing it in an if/else statement. If the condition is true execute the following code else execute the same code without password and confirm_password properties.
I found that it is repetition of code. Is there nicer way I can mention properties conditionally inside the object?
$scope.newStudentForm = {
rules: {
firstname: {
required: true
},
lastname: {
required: true
},
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 6
},
confirm_password: {
required: true,
minlength: 6,
equalTo: "#password"
},
student_role: "required"
},
required: false,?'key' : (condition) ? 'value when condition satisfied' : 'value when condition failed'