diff --git a/public/docs/js/latest/guide/_data.json b/public/docs/js/latest/guide/_data.json index 925419e690..975457341f 100644 --- a/public/docs/js/latest/guide/_data.json +++ b/public/docs/js/latest/guide/_data.json @@ -13,8 +13,8 @@ "title": "User Input" }, - "creating-components": { - "title": "Creating Components" + "making-components": { + "title": "Making Components" }, "talking-to-components": { diff --git a/public/docs/js/latest/guide/creating-components.jade b/public/docs/js/latest/guide/creating-components.jade deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/public/docs/js/latest/guide/making-components.jade b/public/docs/js/latest/guide/making-components.jade new file mode 100644 index 0000000000..356497e320 --- /dev/null +++ b/public/docs/js/latest/guide/making-components.jade @@ -0,0 +1,99 @@ +.l-main-section + p. + Mission: By the end of this chapter, you should be able to create a child component and render + it within a parent component. You should also be able to bind to the child component. + + .l-sub-section + h3#section-examples Examples: + ul + li + a(href='') TypeScript + li + a(href='') ES5 + + p. + As mentioned earlier, you build Angular applications as a tree of nested components. You've seen how to create + a top-level component. You add child components to a parent component by using them in the parent component's + template. + p. + Given a bootstrapping template with a <parent> tag in the body, you can create a parent + component that uses a <child> component like so: + + pre.prettyprint.linenums.lang-javascript + code. + //ES5 + function ParentComponent() { + this.message = "I'm the parent"; + } + ParentComponent.annotations = [ + new angular.Component({ + selector: "parent" + }), + new angular.View({ + template: + '<h1>{{ message }}</h1>' + + '<child></child>', + directives: [ChildComponent] + }) + ]; + + pre.prettyprint.linenums.lang-typescript + code. + //TypeScript + @Component({ + selector: 'parent' + }) + @View({ + template: ` + <h1>{{ message }}</h1> + <child></child> + `, + directives: [ChildComponent] + }) + class ParentComponent { + message: string; + + constructor() { + this.message = "I'm the parent"; + } + } + + p You then just need to write the ChildComponent class to make it work: + + pre.prettyprint.linenums.lang-javascript + code. + //ES5 + function ChildComponent() { + this.message = "I'm the child"; + } + ChildComponent.annotations = [ + new angular.Component({ + selector: "child" + }), + new angular.View({ + template: '<p> {{ message }} </p>' + }) + ]; + + pre.prettyprint.linenums.lang-typescript + code. + //TypeScript + @Component({ + selector: 'child' + }) + @View({ + template: ` + <p> {{ message }} </p> + ` + }) + class ChildComponent { + constructor() { + this.message = "I'm the child"; + } + } + + p. + Notice that in addition to using the <child> element in the parent template, you also need to + add ChildComponent in ParentComponent's list of directives + p. + [TODO: Motivate communication between components with iterator example that passes index to the child]