| Start | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Basic Components and LifeCycle Hooks What’s a component?Component Markup Using External data in Component:We could add a parameter to pass a name to our component, which would be used as follows: Markup Using Controllers in ComponentsLet’s take a look at how to add a controller to it. Markup CodePen Demo (opens new window) Parameters passed to the component are available in the controller's scope just before its In the template from above, this would render "Hello John, I'm MacJohn!". Note that Using “require” as an ObjectIn some instances you may need to access data from a parent component inside your component. This can be achieved by specifying that our component requires that parent component, the require will give us reference to the required component controller, which can then be used in our controller as shown in the example below: Notice that required controllers are guaranteed to be ready only after the $onInit hook. Keep in mind, though, that this creates a tight coupling (opens new window) between the child and the parent. |
||||||||||||||||||||||||
| Components In angular JS The components in angularJS can be visualised as a custom directive (< html > this in an HTML directive, and something like this will be a custom directive < ANYTHING >). A component contains a view and a controller. Controller contains the business logic which is binded with an view , which the user sees. The component differs from a angular directive because it contains less configuration. An angular component can be defined like this. Components are defined on the angular modules. They contains two arguments, One is the name of the component and second one is a object which contains key value pair, which defines which view and which controller it is going to use like this . "myApp" is the name of the app we are building and customer is the name of our component. Now for calling it in main html file we will just put it like this Now this directive will be replaced by the view you have specified and the business logic you have written in your controller. NOTE : Remember component take a object as second argument while directive take a factory function as argument. Parameters
RemarksComponent is a special kind of directive that uses a simpler configuration which is suitable for a component-based application structure. Components were introduced in Angular 1.5, the examples in this section will not work with older AngularJS versions. A complete developer guide about Components is avalable on https://docs.angularjs.org/guide/component (opens new window) |
Read Article
https://develop.horje.com/learn/1434/reference