Friday 27 March 2015

Angularjs directive

a

directive in  module ng

Modifies the default behavior of the html A tag so that the default action is prevented when the href attribute is empty.
This change permits the easy creation of action links with the ngClick directive without changing the location or causing page reloads,


 e.g.: <a href="" ng-click="list.addItem()">Add Item</a>


form

  1. - directive in module ng
Directive that instantiates FormController.
If the name attribute is specified, the form controller is published onto the current scope under this name.

Alias: ngForm

In Angular, forms can be nested. This means that the outer form is valid when all of the child forms are valid as well. However, browsers do not allow nesting of <form> elements, so Angular provides the ngForm directive which behaves identically to <form> but can be nested. This allows you to have nested forms, which is very useful when using Angular validation directives in forms that are dynamically generated using the ngRepeat directive. Since you cannot dynamically generate the name attribute of input elements using interpolation, you have to wrap each set of repeated inputs in an ngForm directive and nest these in an outer form element.

CSS classes

  • ng-valid is set if the form is valid.
  • ng-invalid is set if the form is invalid.
  • ng-pristine is set if the form is pristine.
  • ng-dirty is set if the form is dirty.
  • ng-submitted is set if the form was submitted.
Keep in mind that ngAnimate can detect each of these classes when added and removed.

Submitting a form and preventing the default action

Since the role of forms in client-side Angular applications is different than in classical roundtrip apps, it is desirable for the browser not to translate the form submission into a full page reload that sends the data to the server. Instead some javascript logic should be triggered to handle the form submission in an application-specific way.
For this reason, Angular prevents the default action (form submission to the server) unless the <form> element has an action attribute specified.
You can use one of the following two ways to specify what javascript method should be called when a form is submitted:
  • ngSubmit directive on the form element
  • ngClick directive on the first button or input field of type submit (input[type=submit])
To prevent double execution of the handler, use only one of the ngSubmit or ngClick directives. This is because of the following form submission rules in the HTML specification:
  • If a form has only one input field then hitting enter in this field triggers form submit (ngSubmit)
  • if a form has 2+ input fields and no buttons or input[type=submit] then hitting enter doesn't trigger submit
  • if a form has one or more input fields and one or more buttons or input[type=submit] then hitting enter in any of the input fields will trigger the click handler on the first button or input[type=submit] (ngClick) and a submit handler on the enclosing form (ngSubmit)
Any pending ngModelOptions changes will take place immediately when an enclosing form is submitted. Note that ngClick events will occur before the model is updated. Use ngSubmit to have access to the updated model.

Animation Hooks

Animations in ngForm are triggered when any of the associated CSS classes are added and removed. These classes are: .ng-pristine, .ng-dirty, .ng-invalid and .ng-valid as well as any other validations that are performed within the form. Animations in ngForm are similar to how they work in ngClass and animations can be hooked into using CSS transitions, keyframes as well as JS animations.
The following example shows a simple way to utilize CSS transitions to style a form element that has been rendered as invalid after it has been validated:
//be sure to include ngAnimate as a module to hook into more
//advanced animations
.my-form {
  transition:0.5s linear all;
  background: white;
}
.my-form.ng-invalid {
  background: red;
  color:white;
}

Directive Info

  • This directive executes at priority level 0.

Usage

  • as element:
    <form
      [name=""]>
    ...
    </form>
     
     
     

    input

    1. - directive in module ng
    HTML input element control. When used together with ngModel, it provides data-binding, input state control, and validation. Input control follows HTML5 input types and polyfills the HTML5 validation behavior for older browsers.

    Usage

    • as element:
      <input
        ng-model=""
        [name=""]
        [required=""]
        [ng-required=""]
        [ng-minlength=""]
        [ng-maxlength=""]
        [ng-pattern=""]
        [ng-change=""]
        [ng-trim=""]>
      ...
      </input>
       
       
       
       
      
      
      
      
      
      
      

      input[checkbox]

      1. - input in module ng
               HTML checkbox.

      Directive Info

    • This directive executes at priority level 0.

    Usage

    <input type="checkbox" ng-model="" [name=""] [ng-true-value=""] [ng-false-value=""] [ng-change=""]>
     
     

    input[date]

    1. - input in module ng
    Input with date validation and transformation. In browsers that do not yet support the HTML5 date input, a text element will be used. In that case, text must be entered in a valid ISO-8601 date format (yyyy-MM-dd), for example: 2009-01-06. Since many modern browsers do not yet support this input type, it is important to provide cues to users on the expected input format via a placeholder or label.
    The model must always be a Date object, otherwise Angular will throw an error. Invalid Date objects (dates whose getTime() is NaN) will be rendered as an empty string.
    The timezone to be used to read/write the Date instance in the model can be defined using ngModelOptions. By default, this is the timezone of the browser.


     

    Usage

    <input type="date"
           ng-model=""
           [name=""]
           [min=""]
           [max=""]
           [required=""]
           [ng-required=""]
           [ng-change=""]>

     

Thursday 12 March 2015

Git Basic and Tags

Initializing a Repository in an Existing Directory

git init

Cloning an Existing Repository

If you want to get a copy of an existing Git repository—for example, a project you’d like to
contribute to—the command you need is git clone
You clone a repository with git clone [URL]. For example, if you want to clone the Ruby
Git library called Grit, you can do so like this:

git clone git://github.com/sonam/grit.git


That creates a directory named grit,initializes a *git directory inside it, pulls down all
the data for that repository, and checks out a working copy of the latest version.

Recording Changes to the Repository


You have a bona fide Git repository and a checkout or working copy of the files for that project.
Remember that each file in your working directory can be in one of two states: tracked or
untracked. Tracked files are files that were in the last snapshot; they can be unmodified, modi-
fied, or staged. Untracked files are everything else—any files in your working directory that
were not in your last snapshot and are not in your staging area. When you first clone a repository,
all of your files will be tracked and unmodified because you just checked them out and haven’t
edited anything.



Checking the Status of Your Files

git status

Tracking New Files

git add [name of file]

Skipping the Staging Area


git commit -a -m "message"

Viewing the Commit History

After you have created several commits, or if you have cloned a repository with an existing
commit history, you’ll probably want to look back to see what has happened.

git log

or 

git log --stat

One of the more helpful options is -p  which shows the diff introduced in each commit.
You can also use -2 ,which limits the output to only the last two entries:

git log -p -2

Undoing Things

At any stage, you may want to undo something. Here, I’ll review a few basic tools for undoing
changes that you have made. Be careful, because you can’t always undo some of these undos.
This is one of the few areas in Git where you may lose some work if you do it wrong.

Changing Your Last Commit

One of the common undos takes place when you commit too early and possibly forget to add
some files, or you mess up your commit message. If you want to try that commit again, you
can run commit with the --amend option:

git commit --amend

This command takes your staging area and uses it for the commit.
And then you can add and commit that file.

Adding Remote Repositories

git remote add  [URL]

Fetching and Pulling from Your Remotes

git fetch [remote-name]

Pushing to Your Remotes

git push origin master


Listing Your Tags



git tag

Creating Tags

Git uses two main types of tags: lightweight and annotated. A lightweight tag is very much like
a branch that does not change—it’s just a pointer to a specific commit. Annotated tags, how-
ever, are stored as full objects in the Git database. They’re check-summed; contain the tagger
name, e-mail, and date; have a tagging message; and can be signed and verified with GNU Pri-
vacy Guard (GPG). It’s generally recommended that you create annotated tags so you can have
all this information; but if you want a temporary tag or for some reason don’t want to keep the
other information, lightweight tags are available too.



Annotated Tags

Creating an annotated tag in Git is simple. The easiest way is to specify -a when you run the
tag command:

git tag -a [name of tag] -m "message"

Signed Tags

You can also sign your tags with GPG, assuming you have a private key.

git tag -s [name of tag] -m "message"

Lightweight Tags

Another way to tag commits is with a lightweight tag.This is basically the commit checksum
stored in a file—no other information is kept.

git tag [name of tag] -lw

Verifying Tags

To verify a signed tag

git tag -v [name of tag]

Sharing Tags

 The git push command does not transfer tags to remote servers. You have to explic-
itly push tags to a shared server after you create them. This process is just like sharing remote
branches—you can run

git push origin [name of tag]

If you have a lot of tags that you want to push up at once

git push origin --tag