Advanced Editing with Forms

In our previous example we made a very simple form. What if we wish to make something more complex? Here we would like the user to store an ingredient list for single serving, and then let the form compute ingredient amount needed for n-servings.

Repeater

A single recipe has one or more ingredients. Since the count is different for each recipe, we need a way to let the user control the structure of both the template as well as the document. The ng-repeat allows you to replicate a portion of the document any number of times. Notice that when ng-repeat binds to the document it automatically creates an Array in that location. To add a new row we use recipe.ingredients.$add(); to remove a row we use recipe.ingredients.$remove(ingredient). These actions are triggered by clicking on the link having attribute ng-action.

Scope

When ng-repeat unrolls it assigns each ingredient to a local scope variable ingredient. The ingredient variable only has value within the ng-repeat scope.

Also notice, that we have created a servings variable, which is not part of a document. This means that its value will not be persisted when you save the document or reopen it.