Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit b971a31

Browse files
committed
step-4 Directory and File Organization
- Refactor the layout of files and directories, applying best practices and techniques that will make the application easier to maintain and expand in the future: - Put each entity in its own file. - Organize code by feature area (instead of by function). - Split code into modules that other modules can depend on. - Use external templates in `.html` files (instead of inline HTML strings).
1 parent 5981bd3 commit b971a31

7 files changed

+23
-15
lines changed

app/app.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

app/app.module.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
// Define the `phonecatApp` module
4+
angular.module('phonecatApp', [
5+
// ...which depends on the `phoneList` module
6+
'phoneList'
7+
]);

app/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
77
<link rel="stylesheet" href="app.css" />
88
<script src="bower_components/angular/angular.js"></script>
9-
<script src="app.js"></script>
10-
<script src="phone-list.component.js"></script>
9+
<script src="app.module.js"></script>
10+
<script src="phone-list/phone-list.module.js"></script>
11+
<script src="phone-list/phone-list.component.js"></script>
1112
</head>
1213
<body>
1314

app/phone-list.component.js renamed to app/phone-list/phone-list.component.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@
22

33
// Register `phoneList` component, along with its associated controller and template
44
angular.
5-
module('phonecatApp').
5+
module('phoneList').
66
component('phoneList', {
7-
template:
8-
'<ul>' +
9-
'<li ng-repeat="phone in $ctrl.phones">' +
10-
'<span>{{phone.name}}</span>' +
11-
'<p>{{phone.snippet}}</p>' +
12-
'</li>' +
13-
'</ul>',
7+
templateUrl: 'phone-list/phone-list.template.html',
148
controller: function PhoneListController() {
159
this.phones = [
1610
{

app/phone-list.component.spec.js renamed to app/phone-list/phone-list.component.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe('phoneList', function() {
44

55
// Load the module that contains the `phoneList` component before each test
6-
beforeEach(module('phonecatApp'));
6+
beforeEach(module('phoneList'));
77

88
// Test the controller
99
describe('PhoneListController', function() {

app/phone-list/phone-list.module.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'use strict';
2+
3+
// Define the `phoneList` module
4+
angular.module('phoneList', []);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<ul>
2+
<li ng-repeat="phone in $ctrl.phones">
3+
<span>{{phone.name}}</span>
4+
<p>{{phone.snippet}}</p>
5+
</li>
6+
</ul>

0 commit comments

Comments
 (0)