Skip to content

Commit 1251d6a

Browse files
author
simpulton
committed
Clean up with state!
1 parent 0d12a27 commit 1251d6a

File tree

6 files changed

+98
-39
lines changed

6 files changed

+98
-39
lines changed

css/website.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#header h1#logo {
1111
float: left;
12+
margin: 0;
1213
}
1314

1415
#header h1#logo a {

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
<html ng-app="website">
33
<head>
44
<title>AngularJS Website</title>
5-
6-
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
7-
<script type="text/javascript" src="js/website.js"></script>
8-
<link rel="stylesheet" href="css/bootstrap/css/bootstrap.min.css">
5+
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" rel="stylesheet">
96
<link rel="stylesheet" href="css/website.css">
107
</head>
118
<body>
@@ -27,5 +24,8 @@ <h1 id="logo"><a href="#/home"></a></h1>
2724
<div id="container">
2825
<div ng-view></div>
2926
</div>
27+
28+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
29+
<script type="text/javascript" src="js/website.js"></script>
3030
</body>
3131
</html>

js/website.js

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,54 @@
11
angular.module('website', []).
2-
config(function($routeProvider) {
2+
config(function ($routeProvider) {
33
$routeProvider.
4-
when('/about', {templateUrl:'partials/basic-template.html', controller:AboutCtrl}).
5-
when('/experiments', {templateUrl:'partials/basic-template.html', controller:ExperimentsCtrl }).
6-
when('/home', {templateUrl:'partials/basic-template.html', controller:HomeCtrl }).
7-
otherwise({redirectTo:'/home'});
8-
});
9-
10-
function AboutCtrl($scope) {
11-
$scope.title = 'About Page';
12-
$scope.body = 'This is the about page body';
13-
}
14-
15-
function ExperimentsCtrl($scope) {
16-
$scope.title = 'Experiments Page';
17-
$scope.body = 'This is the about experiments body';
18-
}
19-
20-
function HomeCtrl($scope) {
21-
$scope.title = 'Home Page';
22-
$scope.body = 'This is the about home body';
23-
}
4+
when('/about', {templateUrl: 'partials/about.html', controller: 'AboutCtrl'}).
5+
when('/experiments', {templateUrl: 'partials/experiments.html', controller: 'ExperimentsCtrl'}).
6+
when('/home', {templateUrl: 'partials/home.html', controller: 'HomeCtrl'}).
7+
otherwise({redirectTo: '/home'});
8+
})
9+
.controller('AboutCtrl', ['$scope', 'StateService', function ($scope, StateService) {
10+
$scope.title = 'About Page';
11+
$scope.body = 'This is the about page body';
12+
13+
$scope.message = StateService.getMessage();
14+
15+
$scope.updateMessage = function (m) {
16+
StateService.setMessage(m);
17+
};
18+
}])
19+
.controller('ExperimentsCtrl', ['$scope', 'StateService', function ($scope, StateService) {
20+
$scope.title = 'Experiments Page';
21+
$scope.body = 'This is the about experiments body';
22+
23+
$scope.message = StateService.getMessage();
24+
25+
$scope.updateMessage = function (m) {
26+
StateService.setMessage(m);
27+
};
28+
}])
29+
.controller('HomeCtrl', ['$scope', 'StateService', function ($scope, StateService) {
30+
$scope.title = 'Home Page';
31+
$scope.body = 'This is the about home body';
32+
33+
$scope.message = StateService.getMessage();
34+
35+
$scope.updateMessage = function (m) {
36+
StateService.setMessage(m);
37+
};
38+
}])
39+
.factory('StateService', function () {
40+
var message = 'Hello Message';
41+
var getMessage = function() {
42+
return message;
43+
};
44+
var setMessage = function(m) {
45+
message = m;
46+
47+
console.log('Message Yo!', message);
48+
};
49+
50+
return {
51+
getMessage: getMessage,
52+
setMessage: setMessage
53+
}
54+
});

partials/about.html

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
<div>
2-
<h1><strong>Hello.</strong></h1>
2+
<h1><strong>Hello.</strong></h1>
33

4-
<h2>My name is Lukas and I am an independent interactive developer from Phoenix, AZ. <strong>I
5-
like to fail and fail fast</strong>.</h2>
4+
<h2>My name is Lukas and I am an independent interactive developer from Phoenix, AZ. <strong>I
5+
like to fail and fail fast</strong>.</h2>
66
</div>
77

88
<div>
9-
<p>
10-
If we are ever in the same placee, please say <strong>"hello"</strong>. I love to
11-
<strong>geek out</strong>!
12-
</p>
13-
</div>
9+
<p>
10+
If we are ever in the same place, please say <strong>"hello"</strong>. I love to
11+
<strong>geek out</strong>!
12+
</p>
13+
</div>
14+
15+
<hr>
16+
<div>
17+
<h2 class="text-error">{{message}}</h2>
18+
<form class="form-inline">
19+
<input type="text" ng-model="message" placeholder="Message">
20+
<button type="submit" class="btn" ng-click="updateMessage(message)">Update Message</button>
21+
</form>
22+
</div>

partials/experiments.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ <h2>I wonder what would happen if I changed <strong>this variable</strong> to
1111
nudge there.
1212
</p>
1313
</div>
14+
15+
<hr>
16+
<div>
17+
<h2 class="text-error">{{message}}</h2>
18+
<form class="form-inline">
19+
<input type="text" ng-model="message" placeholder="Message">
20+
<button type="submit" class="btn" ng-click="updateMessage(message)">Update Message</button>
21+
</form>
22+
</div>

partials/home.html

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
<div>
2-
<h1><strong>Welcome</strong></h1>
2+
<h1><strong>Welcome</strong></h1>
33

4-
<h2>This is <strong>my playground</strong> for testing out ideas and really when you get down to
5-
it... <strong>just having fun</strong>.</h2>
4+
<h2>This is <strong>my playground</strong> for testing out ideas and really when you get down to
5+
it... <strong>just having fun</strong>.</h2>
66
</div>
77

88
<div>
9-
<p>
10-
I hope you learn something while you are here. That would make me <strong>really happy</strong>.
11-
</p>
9+
<p>
10+
I hope you learn something while you are here. That would make me <strong>really happy</strong>.
11+
</p>
1212
</div>
13+
14+
<hr>
15+
<div>
16+
<h2 class="text-error">{{message}}</h2>
17+
<form class="form-inline">
18+
<input type="text" ng-model="message" placeholder="Message">
19+
<button type="submit" class="btn" ng-click="updateMessage(message)">Update Message</button>
20+
</form>
21+
</div>

0 commit comments

Comments
 (0)