mirror of
https://github.com/apache/struts.git
synced 2026-08-06 23:27:07 +00:00
Use ControllerAs pattern in angularjs archetype
This commit is contained in:
+1
-1
@@ -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>
|
||||
|
||||
|
||||
+2
-2
@@ -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' });
|
||||
}
|
||||
]);
|
||||
|
||||
+10
-9
@@ -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();
|
||||
}
|
||||
}
|
||||
})();
|
||||
+2
-4
@@ -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() {
|
||||
|
||||
|
||||
+3
-4
@@ -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";
|
||||
}
|
||||
})();
|
||||
+2
-2
@@ -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>
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
<ul>
|
||||
<li ng-repeat="project in projects">{{project}}</li>
|
||||
<li ng-repeat="project in vm.projects">{{project}}</li>
|
||||
</ul>
|
||||
Reference in New Issue
Block a user