2011-05-11 00:45:42 +00:00
|
|
|
@ngdoc overview
|
2011-06-06 15:50:35 +00:00
|
|
|
@name Tutorial: 0 - angular-seed
|
2011-05-02 17:16:50 +00:00
|
|
|
@description
|
|
|
|
|
|
2011-06-06 15:50:35 +00:00
|
|
|
<ul doc:tutorial-nav="0"></ul>
|
|
|
|
|
|
|
|
|
|
|
2011-07-29 19:40:14 +00:00
|
|
|
You are now ready to build the Angular phonecat application. In this step, you will become familiar
|
|
|
|
|
with the most important source code files, learn how to start the development servers bundled with
|
2011-05-02 23:40:31 +00:00
|
|
|
angular-seed, and run the application in the browser.
|
2011-05-02 17:16:50 +00:00
|
|
|
|
2011-05-11 00:45:42 +00:00
|
|
|
|
2011-06-06 15:50:35 +00:00
|
|
|
<doc:tutorial-instructions show="true">
|
|
|
|
|
<doc:tutorial-instruction id="git-mac" title="Git on Mac/Linux">
|
|
|
|
|
<ol>
|
|
|
|
|
<li><p>In angular-phonecat directory, run this command:</p>
|
|
|
|
|
<pre><code>git checkout -f step-0</code></pre>
|
2011-06-07 05:02:30 +00:00
|
|
|
<p>This resets your workspace to step 0 of the tutorial app.</p>
|
2011-06-06 15:50:35 +00:00
|
|
|
<p>You must repeat this for every future step in the tutorial and change the number to
|
|
|
|
|
the number of the step you are on. This will cause any changes you made within
|
|
|
|
|
your working directory to be lost.</p></li>
|
|
|
|
|
|
|
|
|
|
<li>To see the app running in a browser, do one of the following:
|
|
|
|
|
<ul>
|
|
|
|
|
<li><b>For node.js users:</b>
|
|
|
|
|
<ol>
|
|
|
|
|
<li>In a <i>separate</i> terminal tab or window, run
|
|
|
|
|
<code>./scripts/web-server.js</code> to start the web server.</li>
|
|
|
|
|
<li>Open a browser window for the app and navigate to <a
|
|
|
|
|
href="http://localhost:8000/app/index.html">http://localhost:8000/app/index.html</a></li>
|
|
|
|
|
</ol>
|
|
|
|
|
</li>
|
|
|
|
|
<li><b>For other http servers:</b>
|
|
|
|
|
<ol>
|
|
|
|
|
<li>Configure the server to serve the files in the <code>angular-phonecat</code>
|
|
|
|
|
directory.</li>
|
|
|
|
|
<li>Navigate in your browser to
|
|
|
|
|
<code>http://localhost:[port-number]/[context-path]/app/index.html</code>.</li>
|
|
|
|
|
</ol>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
|
|
|
|
</ol>
|
|
|
|
|
</doc:tutorial-instruction>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<doc:tutorial-instruction id="git-win" title="Git on Windows">
|
|
|
|
|
<ol>
|
|
|
|
|
<li><p>Open msysGit bash and run this command (in angular-phonecat directory):</p>
|
|
|
|
|
<pre><code>git checkout -f step-0</code></pre>
|
2011-06-07 05:02:30 +00:00
|
|
|
<p>This resets your workspace to step 0 of the tutorial app.</p>
|
2011-06-06 15:50:35 +00:00
|
|
|
<p>You must repeat this for every future step in the tutorial and change the number to
|
|
|
|
|
the number of the step you are on. This will cause any changes you made within
|
|
|
|
|
your working directory to be lost.</p></li>
|
|
|
|
|
<li>To see the app running in a browser, do one of the following:
|
|
|
|
|
<ul>
|
|
|
|
|
<li><b>For node.js users:</b>
|
|
|
|
|
<ol>
|
|
|
|
|
<li>In a <i>separate</i> terminal tab or window, run <code>node
|
|
|
|
|
scripts\web-server.js</code> to start the web server.</li>
|
|
|
|
|
<li>Open a browser window for the app and navigate to <a
|
|
|
|
|
href="http://localhost:8000/app/index.html">http://localhost:8000/app/index.html</a></li>
|
|
|
|
|
</ol>
|
|
|
|
|
</li>
|
|
|
|
|
<li><b>For other http servers:</b>
|
|
|
|
|
<ol>
|
|
|
|
|
<li>Configure the server to serve the files in the <code>angular-phonecat</code>
|
|
|
|
|
directory.</li>
|
|
|
|
|
<li>Navigate in your browser to
|
|
|
|
|
<code>http://localhost:[port-number]/[context-path]/app/index.html</code>.</li>
|
|
|
|
|
</ol>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
|
|
|
|
</ol>
|
|
|
|
|
</doc:tutorial-instruction>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<doc:tutorial-instruction id="ss-mac" title="Snapshots on Mac/Linux">
|
|
|
|
|
<ol>
|
2011-07-29 19:40:14 +00:00
|
|
|
<li><p>In the angular-phonecat directory, run this command:</p>
|
2011-06-06 15:50:35 +00:00
|
|
|
<pre><code>./goto_step.sh 0</code></pre>
|
2011-06-07 05:02:30 +00:00
|
|
|
<p>This resets your workspace to step 0 of the tutorial app.</p>
|
2011-06-06 15:50:35 +00:00
|
|
|
<p>You must repeat this for every future step in the tutorial and change the number to
|
|
|
|
|
the number of the step you are on. This will cause any changes you made within
|
|
|
|
|
your working directory to be lost.</p></li>
|
|
|
|
|
<li>To see the app running in a browser, do one of the following:
|
|
|
|
|
<ul>
|
|
|
|
|
<li><b>For node.js users:</b>
|
|
|
|
|
<ol>
|
|
|
|
|
<li>In a <i>separate</i> terminal tab or window, run
|
|
|
|
|
<code>./scripts/web-server.js</code> to start the web server.</li>
|
|
|
|
|
<li>Open a browser window for the app and navigate to <a
|
|
|
|
|
href="http://localhost:8000/app/index.html">http://localhost:8000/app/index.html</a></li>
|
|
|
|
|
</ol>
|
|
|
|
|
</li>
|
|
|
|
|
<li><b>For other http servers:</b>
|
|
|
|
|
<ol>
|
|
|
|
|
<li>Configure the server to serve the files in the angular-phonecat
|
|
|
|
|
<code>sandbox</code> directory.</li>
|
|
|
|
|
<li>Navigate in your browser to
|
|
|
|
|
<code>http://localhost:[port-number]/[context-path]/app/index.html</code>.</li>
|
|
|
|
|
</ol>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
|
|
|
|
</ol>
|
|
|
|
|
</doc:tutorial-instruction>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<doc:tutorial-instruction id="ss-win" title="Snapshots on Windows">
|
|
|
|
|
<ol>
|
2011-07-29 19:40:14 +00:00
|
|
|
<li><p>Open windows command line and run this command (in the angular-phonecat directory):</p>
|
2011-06-06 15:50:35 +00:00
|
|
|
<pre><code>goto_step.bat 0</code></pre>
|
2011-06-07 05:02:30 +00:00
|
|
|
<p>This resets your workspace to step 0 of the tutorial app.</p>
|
2011-06-06 15:50:35 +00:00
|
|
|
<p>You must repeat this for every future step in the tutorial and change the number to
|
|
|
|
|
the number of the step you are on. This will cause any changes you made within
|
|
|
|
|
your working directory to be lost.</p></li>
|
|
|
|
|
<li>To see the app running in a browser, do one of the following:
|
|
|
|
|
<ul>
|
|
|
|
|
<li><b>For node.js users:</b>
|
|
|
|
|
<ol>
|
|
|
|
|
<li>In a <i>separate</i> terminal tab or window, run <code>node
|
|
|
|
|
scripts\web-server.js</code> to start the web server.</li>
|
|
|
|
|
<li>Open a browser window for the app and navigate to <a
|
|
|
|
|
href="http://localhost:8000/app/index.html">http://localhost:8000/app/index.html</a></li>
|
|
|
|
|
</ol>
|
|
|
|
|
</li>
|
|
|
|
|
<li><b>For other http servers:</b>
|
|
|
|
|
<ol>
|
|
|
|
|
<li>Configure the server to serve the files in the angular-phonecat
|
|
|
|
|
<code>sandbox</code> directory.</li>
|
|
|
|
|
<li>Navigate in your browser to
|
|
|
|
|
<code>http://localhost:[port-number]/[context-path]/app/index.html</code>.</li>
|
|
|
|
|
</ol>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</li>
|
|
|
|
|
</ol>
|
|
|
|
|
</doc:tutorial-instruction>
|
|
|
|
|
</doc:tutorial-instructions>
|
2011-05-02 17:16:50 +00:00
|
|
|
|
2011-05-11 00:45:42 +00:00
|
|
|
|
|
|
|
|
You can now see the page in your browser. It's not very exciting, but that's OK.
|
2011-05-02 17:16:50 +00:00
|
|
|
|
2011-05-11 00:45:42 +00:00
|
|
|
The static HTML page that displays "Nothing here yet!" was constructed with the HTML code shown
|
2011-07-29 19:40:14 +00:00
|
|
|
below. The code contains some key Angular elements that we will need going forward.
|
2011-05-11 00:45:42 +00:00
|
|
|
|
2011-05-02 17:16:50 +00:00
|
|
|
__`app/index.html`:__
|
|
|
|
|
<pre>
|
|
|
|
|
<!doctype html>
|
|
|
|
|
<html xmlns:ng="http://angularjs.org/">
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<title>my angular app</title>
|
|
|
|
|
<link rel="stylesheet" href="css/app.css"/>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
|
|
Nothing here yet!
|
|
|
|
|
|
|
|
|
|
<script src="lib/angular/angular.js" ng:autobind></script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
</pre>
|
|
|
|
|
|
2011-05-11 00:45:42 +00:00
|
|
|
|
|
|
|
|
|
2011-05-02 17:16:50 +00:00
|
|
|
## What is the code doing?
|
|
|
|
|
|
2011-05-11 00:45:42 +00:00
|
|
|
* xmlns declaration
|
|
|
|
|
|
2011-06-06 15:50:35 +00:00
|
|
|
<html xmlns:ng="http://angularjs.org">
|
2011-05-11 00:45:42 +00:00
|
|
|
|
2011-07-29 19:40:14 +00:00
|
|
|
This `xmlns` declaration for the `ng` namespace must be specified in all Angular applications in
|
|
|
|
|
order to make Angular work with XHTML and IE versions older than 9 (regardless of whether you are
|
2011-05-11 00:45:42 +00:00
|
|
|
using XHTML or HTML).
|
|
|
|
|
|
2011-07-29 19:40:14 +00:00
|
|
|
* Angular script tag
|
2011-05-11 00:45:42 +00:00
|
|
|
|
2011-06-06 15:50:35 +00:00
|
|
|
<script src="lib/angular/angular.js" ng:autobind>
|
2011-05-11 00:45:42 +00:00
|
|
|
|
|
|
|
|
This single line of code is all that is needed to bootstrap an angular application.
|
|
|
|
|
|
|
|
|
|
The code downloads the `angular.js` script and registers a callback that will be executed by the
|
2011-07-29 19:40:14 +00:00
|
|
|
browser when the containing HTML page is fully downloaded. When the callback is executed, Angular
|
|
|
|
|
looks for the {@link api/angular.directive.ng:autobind ng:autobind} attribute. If Angular finds
|
2011-05-11 00:45:42 +00:00
|
|
|
`ng:autobind`, it creates a root scope for the application and associates it with the `<html>`
|
|
|
|
|
element of the template:
|
|
|
|
|
|
2011-06-16 05:31:40 +00:00
|
|
|
<img src="img/tutorial/tutorial_00_final.png">
|
2011-05-11 00:45:42 +00:00
|
|
|
|
2011-07-29 19:40:14 +00:00
|
|
|
As you will see shortly, everything in Angular is evaluated within a scope. We'll learn more
|
2011-05-11 00:45:42 +00:00
|
|
|
about this in the next steps.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## What are all these files in my working directory?
|
|
|
|
|
|
|
|
|
|
Most of the files in your working directory come from the {@link
|
|
|
|
|
https://github.com/angular/angular-seed angular-seed project} which is typically used to bootstrap
|
2011-07-29 19:40:14 +00:00
|
|
|
new Angular projects. The seed project includes the latest Angular libraries, test libraries,
|
2011-05-11 00:45:42 +00:00
|
|
|
scripts and a simple example app, all pre-configured for developing a typical web app.
|
|
|
|
|
|
|
|
|
|
For the purposes of this tutorial, we modified the angular-seed with the following changes:
|
|
|
|
|
|
|
|
|
|
* Removed the example app
|
|
|
|
|
* Added phone images to `app/img/phones`
|
|
|
|
|
* Added phone data files (JSON) to `app/phones`
|
|
|
|
|
|
|
|
|
|
|
2011-05-02 23:40:31 +00:00
|
|
|
# Summary
|
2011-05-02 17:16:50 +00:00
|
|
|
|
2011-07-29 19:40:14 +00:00
|
|
|
Now let's go to {@link step_01 step 1} and add some content to the web app.
|
2011-05-02 17:16:50 +00:00
|
|
|
|
2011-05-11 00:45:42 +00:00
|
|
|
|
2011-06-06 15:50:35 +00:00
|
|
|
<ul doc:tutorial-nav="0"></ul>
|