Book Image

AngularJS Web application development Cookbook

By : Matthew Frisbie
Book Image

AngularJS Web application development Cookbook

By: Matthew Frisbie

Overview of this book

Packed with easy-to-follow recipes, this practical guide will show you how to unleash the full might of the AngularJS framework. Skip straight to practical solutions and quick, functional answers to your problems without hand-holding or slogging through the basics. Avoid antipatterns and pitfalls, and squeeze the maximum amount out of the most powerful parts of the framework, from creating promise-driven applications to building an extensible event bus. Throughout, take advantage of a clear problem-solving approach that offers code samples and explanations of components you should be using in your production applications.
Table of Contents (17 chapters)
AngularJS Web Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working with <select> and ngOptions


AngularJS provides an ngOptions directive to populate the <select> elements in your application. Although this is at first glance a trivial matter, ngOptions utilizes a convoluted comprehension_expression that can populate the dropdown from a data object in a variety of ways.

Getting ready

Assume that your application is as follows:

(app.js)

angular.module('myApp', [])
.controller('Ctrl', function($scope) {
  $scope.players = [
    {
      number: 17,
      name: 'Alshon',
      position: 'WR'
    },
    {
      number: 15,
      name: 'Brandon',
      position: 'WR'
    },
    {
      number: 22,
      name: 'Matt',
      position: 'RB'
    },
    {
      number: 83,
      name: 'Martellus',
      position: 'TE'
    },
    {
      number: 6,
      name: 'Jay',
      position: 'QB'
    }
  ];
  
  $scope.team = {
    '3B': {
      number: 9,
      name: 'Brandon'
    },
    '2B': {
      number: 19,
      name: 'Marco'
    },
    '3B': {
   ...