Forms

Tomasz BiaƂecki

Inspired by

http://www.packtpub.com/sites/default/files/1820OS.jpg

Standard HTML Forms

... are send to server in the form they are shown to the user

... have content type application/x-www-form-urlencoded / multipart/form-data

Forms

... decoupled the model and the view

... allows using any data form

... worries about bidirectional model and view updating

Let's assume we've got the following form...


... and we want to transform it into Angular Form

It's easy ...


 

ngModelController

ngForm directive ...

... creates the following object in scope


myForm: {           //form name
    fistName:{},    //input name
    lastName:{},    //input name
    email:{}        //input name
}
                

ngForm directive ...

... provides validation status


myForm: {                                   //form name
    $dirty: false, $pristine: true,         //dirty or pristine
    $valid: false, $invalid: true,          //valid or invalid
    fistName: {                             //input name
        $dirty: false, $pristine: true,     //dirty or pristine
        $valid: false, $invalid: true,      //valid or invalid
        $error: {                           //validation for field
            required: true,                 //required validation
            minlength: false                //minlength validation
        }
    },
    email: {}                               //input name
}
                

ngForm directive ...

... provides validation status


myForm: {                                   //ngFormController
    $dirty: false, $pristine: true,
    $valid: false, $invalid: true,
    fistName: {                             //ngModelController
        $dirty: false, $pristine: true,
        $valid: false, $invalid: true,
        $error: {
            required: true,
            minlength: false
        }
    },
    email: {}                               //ngModelController
}