| Start |
|---|
| Your First Controller A controller is a basic structure used in Angular to preserve scope and handle certain actions within a page. Each controller is coupled with an HTML view. Below is a basic boilerplate for an Angular app: There are a few things to note here: Setting the app name with We'll need a Javascript file where you define your controllers and their actions/data. The You can have multiple of the same controller (in this case, The Note: Angular employs dual-way data binding, meaning that regardless of how you update the Also note that Angular expressions do not have to reference a controller. An Angular expression can be as simple as
With those things in mind, let's write an implementation of the First, you'll need to instantiate the Angular app in your Javascript. Note that the name we pass here is the same as the name you set in your HTML with the Now that we have the app object, we can use that to create controllers. Note: For anything that we want to be a part of the controller instance, we use the This is all that is required to build a simple controller. |
| Creating Controllers, Minification safe There are a couple different ways to protect your controller creation from minification. The first is called inline array annotation. It looks like the following: The second parameter of the controller method can accept an array of dependencies. As you can see I've defined The second option is using the This does the same thing as inline array annotation but provides a different styling for those that prefer one option over the other. The order of injected dependencies is importantWhen injecting dependencies using the array form, be sure that the list of the dependencies match its corresponding list of arguments passed to the controller function. Note that in the following example, |
| Using ControllerAs in Angular JS In Angular Different ways of using Controller As are - controllerAs View Syntax controllerAs Controller Syntax controllerAs with vm
NOTE: using
|
| Creating Minification-Safe Angular Controllers To create minification-safe angular controllers, you will change the The second argument in the This is different from the normal paradigm; that takes the controller function with the injected arguments. Given: The controller should look like this: Note: The names of injected parameters are not required to match, but they will be bound in order. This will minify to something similar to this: The minification process will replace every instance of |
Creating Controllers Note: The |
| Nested Controllers Nesting controllers chains the Now let's try to handle both of them, nested. Nesting controllers may have it's benefits, but one thing must be kept in mind when doing so. Calling the Syntax
|
Read Article
https://develop.horje.com/learn/1434/reference