Skip to main contentdfsdf

T N's List: Angular

  • Modules

  • MVC

    • In angular, a model is any data that is reachable as a property of an angular Scope object. The name of the property is the model identifier and the value is any JavaScript object (including arrays and primitives).
    • Understanding the Model Component

    1 more annotation...

    • It should contain only the business logic needed for a single view.
    • The most common way to keep controllers slim is by encapsulating work that doesn't belong to controllers into services and then using these services in controllers via dependency injection.

    4 more annotations...

    • In angular, the view is the DOM loaded and rendered in the browser, after angular has transformed the DOM based on information in the template, controller and model.
    • Understanding the View Component
  • Templates/Views/Routes

    • An angular template is the declarative specification that, along with information from the model and controller, becomes the rendered view that a user sees in the browser. It is the static DOM, containing HTML, CSS, and angular-specific elements and angular-specific element attributes. The angular elements and attributes direct angular to add behavior and transform the template DOM into the dynamic view DOM.
      • These are the types of angular elements and element attributes you can use in a template:

          
           
        • Directive — An attribute or element that augments an existing DOM element or represents a reusable DOM component - a widget.
        •  
        • Markup — The double curly brace notation {{ }} to bind expressions to elements is built-in angular markup.
        •  
        • Filter — Formats your data for display to the user.
        •  
        • Form controls — Lets you validate user input.

    1 more annotation...

    • Data-binding in angular web apps is the automatic syncing of data between the model and view components.
    • They are different because first the template (which is the uncompiled HTML along with any additional markup or directives) is compiled on the browser, and second, the compilation step produces a live view. We say live because any changes to the view are immediately reflected in the model, and any changes in the model are propagated to the view. This makes the model always the single-source-of-truth for the application state, greatly simplifying the programming model for the developer. You can think of the view as simply an instant projection of your model.

    1 more annotation...

    • Writing your own filter is very easy: just register a new filter (injectable) factory function with your module. This factory function should return a new filter function which takes the input value as the first argument. Any filter arguments are passed in as additional arguments to the filter function.
    • Services are a feature that angular brings to client-side web apps from the server side, where services have been commonly used for a long time. Services in angular apps are substitutable objects that are wired together using dependency injection (DI). Services are most often used with dependency injection, also a key feature of angular apps.
    • Most applications have a main method which instantiates, wires, and bootstraps the application. Angular apps don't have a main method, instead modules serve the purpose of declaratively specifying how an application should be bootstrapped.

    10 more annotations...

    • Angular services are singletons that carry out specific tasks common to web apps
    • To use an angular service, you identify it as a dependency for the dependent (a controller, or another service) that depends on the service. Angular's dependency injection subsystem takes care of the rest. The angular injector subsystem is in charge of service instantiation, resolution of dependencies, and provision of dependencies to factory functions as requested.

    2 more annotations...

    • It is important that the order of the string identifiers in the array is the same as the order of argument names in the signature of the factory function. Unless the dependencies are inferred from the function signature, it is this array with IDs and their order that the injector uses to determine which services and in which order to inject.
    • Since JavaScript is a dynamic language, DI can't figure out which services to inject by static types (like in static typed languages). Therefore, you can specify the service name by using the $inject property, which is an array containing strings with names of services to be injected. The name must match the corresponding service ID registered with angular. The order of the service IDs matters: the order of the services in the array will be used when calling the factory function with injected parameters. The names of parameters in factory function don't matter, but by convention they match the service IDs, which has added benefits discussed below.
    • Form and controls provide validation services, so that the user can be notified of invalid input.
      • To allow styling of form as well as controls, ngModel add these CSS classes:

          
           
        • ng-valid
        •  
        • ng-invalid
        •  
        • ng-pristine
        •  
        • ng-dirty

    2 more annotations...

    • The only problem I ran into while building the application is the “one route / one view” coupling I alluded to above. As suggested in this thread, you can use <ng:include> to bind partials in the page. The same thread also indicates that multiple <ng:views> per route definition will be supported in the future. I was able to handle the simple UI requirements of this app using one <ng:view> and one <ng:include>. For more complex applications, I’d love the routing infrastructure to allow me to easily and arbitrarily add, remove, change, or animate different elements of the DOM when the route changes in order to support deeper UI transformations. I’m sure there are ways to do this. If Angular.js folks are reading this post, I’d love to hear what they think and what’s coming.
    • In AngularJS, routing is provided by $routeProvider which provides the $route service. We use this service to wire the requested url with the controller and view.
    • In AngularJS, there are module definitions that contain service providers. These providers are responsible for instantiating the services. When an application starts, all the AngularJS modules are loaded and all service providers contained in these modules are registered. When we ask for a service(eg. $route) by mentioning it as an argument in the controller function, AngularJS delegates our request to its dependency injector. The injector then inject the requested service into the controller function after it is instantiated by the corresponding service provider.
    • Is there any progress on supporting multiple views bound to the routing path? The workaround using ng-controller, manually parsing the routing path and binding the template via ng-include seems very cumbersome, if it works at all...
    • you don't have to use templates with routes. Instead, you can use routing to resolve client-side render events.
1 - 20 of 31 Next ›
20 items/page
List Comments (0)