You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by jo...@apache.org on 2015/08/22 12:39:07 UTC
struts git commit: Use ControllerAs pattern in angularjs archetype
Repository: struts
Updated Branches:
refs/heads/master 16fa0ed80 -> 3bd1b7a72
Use ControllerAs pattern in angularjs archetype
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/3bd1b7a7
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/3bd1b7a7
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/3bd1b7a7
Branch: refs/heads/master
Commit: 3bd1b7a7235639c4651eaeae680bc623ebdacf00
Parents: 16fa0ed
Author: Johannes Geppert <jo...@apache.org>
Authored: Sat Aug 22 12:38:51 2015 +0200
Committer: Johannes Geppert <jo...@apache.org>
Committed: Sat Aug 22 12:38:51 2015 +0200
----------------------------------------------------------------------
.../main/webapp/WEB-INF/content/application.jsp | 2 +-
.../src/main/webapp/js/config.js | 4 ++--
.../js/controllers/ApacheProjectsController.js | 19 ++++++++++---------
.../main/webapp/js/controllers/AppController.js | 6 ++----
.../main/webapp/js/controllers/HomeController.js | 7 +++----
.../src/main/webapp/partials/home.html | 4 ++--
.../src/main/webapp/partials/projects.html | 2 +-
7 files changed, 21 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/3bd1b7a7/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/content/application.jsp
----------------------------------------------------------------------
diff --git a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/content/application.jsp b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/content/application.jsp
index 6f5eac7..3f6c374 100644
--- a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/content/application.jsp
+++ b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/content/application.jsp
@@ -16,7 +16,7 @@
<a href="/home">Home</a> - <a href="/projects">Projects</a>
</div>
-<div ng-controller="AppController">
+<div ng-controller="AppController as app">
<div ng-view></div>
</div>
http://git-wip-us.apache.org/repos/asf/struts/blob/3bd1b7a7/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/config.js
----------------------------------------------------------------------
diff --git a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/config.js b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/config.js
index 513760c..9b93aab 100644
--- a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/config.js
+++ b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/config.js
@@ -30,10 +30,10 @@
$routeProvider.when('/projects', {
templateUrl: 'partials/projects.html',
- controller: 'ApacheProjectsController'
+ controller: 'ApacheProjectsController as vm'
}).when('/home', {
templateUrl: 'partials/home.html',
- controller: 'HomeController'
+ controller: 'HomeController as vm'
}).otherwise({ redirectTo: '/home' });
}
]);
http://git-wip-us.apache.org/repos/asf/struts/blob/3bd1b7a7/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/ApacheProjectsController.js
----------------------------------------------------------------------
diff --git a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/ApacheProjectsController.js b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/ApacheProjectsController.js
index 096e3da..1fb0ca9 100644
--- a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/ApacheProjectsController.js
+++ b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/ApacheProjectsController.js
@@ -1,6 +1,4 @@
/*
- * $Id$
- *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -25,15 +23,18 @@
.module('app')
.controller('ApacheProjectsController', ApacheProjectsController);
- function ApacheProjectsController($scope, $log, DataService) {
- this.init = function() {
- DataService.getProjects().then(function(data) {
- $scope.projects = data.projectNames;
+ function ApacheProjectsController($log, DataService) {
+ var vm = this;
+
+ init();
+
+ function init() {
+ return DataService.getProjects().then(function(data) {
+ vm.projects = data.projectNames;
+ return vm.projects;
}, function() {
$log.error('Could not receive project names.');
});
- };
-
- this.init();
+ }
}
})();
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/struts/blob/3bd1b7a7/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/AppController.js
----------------------------------------------------------------------
diff --git a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/AppController.js b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/AppController.js
index 0f1bc2d..d6de31a 100644
--- a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/AppController.js
+++ b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/AppController.js
@@ -1,6 +1,4 @@
/*
- * $Id$
- *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,8 +20,8 @@
'use strict';
angular
- .module('app')
- .controller('AppController', AppController);
+ .module('app')
+ .controller('AppController', AppController);
function AppController() {
http://git-wip-us.apache.org/repos/asf/struts/blob/3bd1b7a7/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/HomeController.js
----------------------------------------------------------------------
diff --git a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/HomeController.js b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/HomeController.js
index d0f23e3..44c7cf9 100644
--- a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/HomeController.js
+++ b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers/HomeController.js
@@ -1,6 +1,4 @@
/*
- * $Id$
- *
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -25,7 +23,8 @@
.module('app')
.controller('HomeController', HomeController);
- function HomeController($scope) {
- $scope.name = "Sunshine";
+ function HomeController() {
+ var vm = this;
+ vm.name = "Sunshine";
}
})();
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/struts/blob/3bd1b7a7/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/partials/home.html
----------------------------------------------------------------------
diff --git a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/partials/home.html b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/partials/home.html
index f147d6e..239f4ea 100644
--- a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/partials/home.html
+++ b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/partials/home.html
@@ -1,6 +1,6 @@
-<h1>Hello, {{name}}.</h1>
+<h1>Hello, {{vm.name}}.</h1>
<p>
Not your name?
- <input type="text" ng-model="name" />
+ <input type="text" ng-model="vm.name" />
</p>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/struts/blob/3bd1b7a7/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/partials/projects.html
----------------------------------------------------------------------
diff --git a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/partials/projects.html b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/partials/projects.html
index ac0f65e..12f4655 100644
--- a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/partials/projects.html
+++ b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/partials/projects.html
@@ -1,3 +1,3 @@
<ul>
- <li ng-repeat="project in projects">{{project}}</li>
+ <li ng-repeat="project in vm.projects">{{project}}</li>
</ul>
\ No newline at end of file