Skip to content
Snippets Groups Projects
Commit e4931777 authored by michaelisvy's avatar michaelisvy
Browse files

migrated from angular-router to ui-router

This article explains well why ui-router now is more popular:
http://www.funnyant.com/angularjs-ui-router/
parent b67ce6b1
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ petClinicApp.config(['$stateProvider', '$urlRouterProvider', function($stateProv ...@@ -36,7 +36,7 @@ petClinicApp.config(['$stateProvider', '$urlRouterProvider', function($stateProv
}). }).
state('app.ownerlist', { state('app.ownerlist', {
url: 'owner/list', url: 'owner/list?lastName',
views: { views: {
'content@': { 'content@': {
templateUrl: 'scripts/app/owner/ownerList.html', templateUrl: 'scripts/app/owner/ownerList.html',
......
...@@ -3,30 +3,31 @@ ...@@ -3,30 +3,31 @@
/* /*
* Owner Search * Owner Search
*/ */
angular.module('controllers').controller('ownerSearchController', ['$scope', '$rootScope', '$resource', '$state', angular.module('controllers').controller('ownerSearchController', ['$scope', '$state',
function($scope, $rootScope, $resource, $state) { function($scope, $state) {
$scope.submitOwnerFindForm = function() { $scope.ownerSearchForm = {};
// form always needs to be initialised
var destUrl = '/petclinic/owner/list?lastName=' // otherwise we can't read $scope.ownerSearchForm.lastName
if(angular.isDefined($scope.ownerFindForm)) {
destUrl += $scope.ownerFindForm.lastName;
}
var ownerResource = $resource(destUrl); $scope.submitOwnerSearchForm = function() {
$rootScope.owners = ownerResource.query(); var lastNameValue;
$state.go('app.ownerlist'); //updating URL in address bar $state.go('app.ownerlist', {lastName: $scope.ownerSearchForm.lastName});
}}]); }}]);
/* /*
* Owners List * Owners List
*/ */
angular.module('controllers').controller('ownerListController', ['$scope', '$rootScope', angular.module('controllers').controller('ownerListController', ['$scope', '$resource', '$stateParams',
function($scope, $rootScope, $location) { function($scope, $resource, $stateParams) {
if ($rootScope.owners!=null){
$scope.ownerList = $rootScope.owners; var destUrl = '/petclinic/owner/list?lastName=';
} if(angular.isDefined($stateParams.lastName)) {
}]); destUrl += $stateParams.lastName;
}
var ownerResource = $resource(destUrl);
$scope.ownerList = ownerResource.query();
}]);
/* /*
* Owners detail (used for both Editable and non-editable pages) * Owners detail (used for both Editable and non-editable pages)
...@@ -46,6 +47,8 @@ function loadOwner($scope, $resource, $stateParams) { ...@@ -46,6 +47,8 @@ function loadOwner($scope, $resource, $stateParams) {
angular.module('controllers').controller('ownerFormController', ['$scope', '$resource', '$http', '$stateParams', '$state', angular.module('controllers').controller('ownerFormController', ['$scope', '$resource', '$http', '$stateParams', '$state',
function($scope, $resource, $http, $stateParams, $state) { function($scope, $resource, $http, $stateParams, $state) {
scope.submitOwnerForm = {};
$scope.submitOwnerForm = function() { $scope.submitOwnerForm = function() {
var form = $scope.owner; var form = $scope.owner;
......
<h2>Find Owners</h2> <h2>Find Ownersss</h2>
<form class="form-horizontal" id="ownerFindForm" data-ng-controller="ownerSearchController"> <form class="form-horizontal" ng-controller="ownerSearchController">
<fieldset> <fieldset>
<div class="control-group" id="lastName"> <div class="control-group" id="lastName">
<label class="control-label">Last name </label> <label class="control-label">Last name </label>
<input ng-model="ownerFindForm.lastName" size="30" maxlength="80"/> <input ng-model="ownerSearchForm.lastName" size="30" maxlength="80"/>
</div> </div>
<div class="form-actions"> <div class="form-actions">
<button type="submit" ng-click="submitOwnerFindForm()">Find Owner</button> <button type="submit" ng-click="submitOwnerSearchForm()">Find Ownerss</button>
</div> </div>
</fieldset> </fieldset>
</form> </form>
<br/> <br/>
<a href="/owners/new">Add Owner</a> <a href="/owners/new">Add Ownerss</a>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment