nl_tokens: @ngdoc directive @name ngForm @restrict EAC
pl_tokens: function ( isNgForm ) { return [ '$timeout' , '$parse' , function ( $timeout , $parse ) { var formDirective = { name : 'form' , restrict : isNgForm ? 'EAC' : 'E' , require : [ 'form' , '^^?form' ] , //first is the form's own ctrl, second is an optional parent form controller : FormController , compile : function ngFormCompile ( formElement , attr ) { // Setup initial state of the control formElement . addClass ( PRISTINE_CLASS ) . addClass ( VALID_CLASS ) ; var nameAttr = attr . name ? 'name' : ( isNgForm && attr . ngForm ? 'ngForm' : false ) ; return { pre : function ngFormPreLink ( scope , formElement , attr , ctrls ) { var controller = ctrls [ 0 ] ; // if `action` attr is not present on the form, prevent the default action (submission) if ( ! ( 'action' in attr ) ) { // we can't use jq events because if a form is destroyed during submission the default // action is not prevented. see #1238 // // IE 9 is not affected because it doesn't fire a submit event and try to do a full // page reload if the form was destroyed by submission of the form via a click handler // on a button in the form. Looks like an IE9 specific bug. var handleFormSubmission = function ( event ) { scope . $apply ( function ( ) { controller . $commitViewValue ( ) ; controller . $setSubmitted ( ) ; } ) ; event . preventDefault ( ) ; } ; formElement [ 0 ] . addEventListener ( 'submit' , handleFormSubmission ) ; // unregister the preventDefault listener so that we don't not leak memory but in a // way that will achieve the prevention of the default action. formElement . <mask> ( '$destroy' , function ( ) { $timeout ( function ( ) { formElement [ 0 ] . removeEventListener ( 'submit' , handleFormSubmission ) ; } , 0 , false ) ; } ) ; } var parentFormCtrl = ctrls [ 1 ] || controller . $$parentForm ; parentFormCtrl . $addControl ( controller ) ; var setter = nameAttr ? getSetter ( controller . $name ) : noop ; if ( nameAttr ) { setter ( scope , controller ) ; attr . $observe ( nameAttr , function ( newValue ) { if ( controller . $name === newValue ) return ; setter ( scope , undefined ) ; controller . $$parentForm . $$renameControl ( controller , newValue ) ; setter = getSetter ( controller . $name ) ; setter ( scope , controller ) ; } ) ; } formElement . on ( '$destroy' , function ( ) { controller . $$parentForm . $removeControl ( controller ) ; setter ( scope , undefined ) ; extend ( controller , nullFormCtrl ) ; //stop propagating child destruction handlers upwards } ) ; } } ; } } ; return formDirective ; function getSetter ( expression ) { if ( expression === '' ) { //create an assignable expression, so forms with an empty name can be renamed later return $parse ( 'this[""]' ) . assign ; } return $parse ( expression ) . assign || noop ; } } ] ; }