From ba59ef495007d192724b352c68e7d2edc53f8b63 Mon Sep 17 00:00:00 2001
From: Igor Minar
Date: Wed, 28 Mar 2012 10:50:46 -0700
Subject: docs(examples): update example apps
---
example/personalLog/personalLog.html | 27 +++++++++++---------
example/personalLog/personalLog.js | 20 ++++-----------
example/personalLog/test/personalLogSpec.js | 39 +++++++++++++++--------------
example/temp.html | 26 ++++++++++++-------
example/view1.html | 2 +-
example/view2.html | 2 +-
6 files changed, 59 insertions(+), 57 deletions(-)
diff --git a/example/personalLog/personalLog.html b/example/personalLog/personalLog.html
index bc7e2e25..77d2ddc2 100644
--- a/example/personalLog/personalLog.html
+++ b/example/personalLog/personalLog.html
@@ -1,28 +1,31 @@
-
+
Personal Log
-
-
+
+
+
+
+
-
-
+
-
Logs:
- -
+
-
{{log.at | date:'yy-MM-dd HH:mm'}} {{log.msg}}
- [x]
+ [x]
diff --git a/example/personalLog/personalLog.js b/example/personalLog/personalLog.js
index 4d182227..c22b8702 100644
--- a/example/personalLog/personalLog.js
+++ b/example/personalLog/personalLog.js
@@ -5,28 +5,23 @@
* - testability of controllers
* - dependency injection for controllers via $inject and constructor function
* - $cookieStore for persistent cookie-backed storage
- * - simple templating constructs such as ng:repeat and {{}}
+ * - simple templating constructs such as ng-repeat and {{}}
* - date filter
* - and binding onSubmit and onClick events to angular expressions
* @author Igor Minar
*/
-
-/** @namespace the 'example' namespace */
-var example = example || {};
-/** @namespace namespace of the personal log app */
-example.personalLog = {};
-
-
//name space isolating closure
(function() {
+var app = angular.module('personalLog', ['ngCookies']);
+
var LOGS = 'logs';
/**
* The controller for the personal log app.
*/
-function LogCtrl($cookieStore, $scope) {
+app.controller('LogCtrl', ['$cookieStore', '$scope', function LogCtrl($cookieStore, $scope) {
var logs = $scope.logs = $cookieStore.get(LOGS) || []; //main model
@@ -72,11 +67,6 @@ function LogCtrl($cookieStore, $scope) {
logs.splice(0, logs.length);
$cookieStore.remove(LOGS);
};
-}
-
-//inject
-LogCtrl.$inject = ['$cookieStore', '$scope'];
+}]);
-//export
-example.personalLog.LogCtrl = LogCtrl;
})();
diff --git a/example/personalLog/test/personalLogSpec.js b/example/personalLog/test/personalLogSpec.js
index ee4fb687..c68fbfc2 100644
--- a/example/personalLog/test/personalLogSpec.js
+++ b/example/personalLog/test/personalLogSpec.js
@@ -1,12 +1,13 @@
describe('example.personalLog.LogCtrl', function() {
var logScope;
- beforeEach(function() {
- var injector = angular.injector(['ng', 'ngMock', 'ngCookies']);
- logScope = injector.get('$rootScope');
- logScope.$cookies = injector.get('$cookies');
- injector.instantiate(example.personalLog.LogCtrl, {$scope: logScope});
- });
+
+ beforeEach(module('personalLog'));
+
+ beforeEach(inject(function($rootScope, $controller) {
+ logScope = $rootScope.$new();
+ $controller('LogCtrl', {$scope: logScope});
+ }));
it('should initialize notes with an empty array', function() {
@@ -43,11 +44,11 @@ describe('example.personalLog.LogCtrl', function() {
});
- it('should store logs in the logs cookie', function() {
- expect(logScope.$cookies.logs).not.toBeDefined();
+ it('should store logs in the logs cookie', inject(function($cookies) {
+ expect($cookies.logs).not.toBeDefined();
logScope.addLog('first log message');
- expect(logScope.$cookies.logs).toBeTruthy();
- });
+ expect($cookies.logs).toBeTruthy();
+ }));
it('should do nothing if newMsg is empty', function() {
@@ -79,17 +80,17 @@ describe('example.personalLog.LogCtrl', function() {
});
- it('should update cookies when a log is deleted', function() {
- expect(logScope.$cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){3}\]/);
+ it('should update cookies when a log is deleted', inject(function($cookies) {
+ expect($cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){3}\]/);
logScope.rmLog(logScope.logs[1]);
- expect(logScope.$cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){2}\]/);
+ expect($cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){2}\]/);
logScope.rmLog(logScope.logs[0]);
logScope.rmLog(logScope.logs[0]);
logScope.rmLog(logScope.logs[0]);
- expect(logScope.$cookies.logs).toMatch(/\[\]/);
- });
+ expect($cookies.logs).toMatch(/\[\]/);
+ }));
});
@@ -110,10 +111,10 @@ describe('example.personalLog.LogCtrl', function() {
});
- it('should remove logs cookie', function() {
- expect(logScope.$cookies.logs).toBeTruthy();
+ it('should remove logs cookie', inject(function($cookies) {
+ expect($cookies.logs).toBeTruthy();
logScope.rmLogs();
- expect(logScope.$cookies.logs).not.toBeDefined();
- });
+ expect($cookies.logs).not.toBeDefined();
+ }));
});
});
diff --git a/example/temp.html b/example/temp.html
index e12b4437..22eb2de7 100644
--- a/example/temp.html
+++ b/example/temp.html
@@ -1,22 +1,30 @@
-
+
angular dev sandbox
-
+
+
-
+
view1 | view2 | blank
- view:
+
+
+
diff --git a/example/view1.html b/example/view1.html
index 158655a6..6d0a5881 100644
--- a/example/view1.html
+++ b/example/view1.html
@@ -1,2 +1,2 @@
view1
-location: {{$service('$location').href}}
+location: {{url()}}
diff --git a/example/view2.html b/example/view2.html
index b53ef7a2..d9545f83 100644
--- a/example/view2.html
+++ b/example/view2.html
@@ -1,2 +1,2 @@
view2
-location: {{$service('$location').href}}
+location: {{url()}}
--
cgit v1.2.3