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
}).
state('app.ownerlist', {
url: 'owner/list',
url: 'owner/list?lastName',
views: {
'content@': {
templateUrl: 'scripts/app/owner/ownerList.html',
......
......@@ -3,30 +3,31 @@
/*
* Owner Search
*/
angular.module('controllers').controller('ownerSearchController', ['$scope', '$rootScope', '$resource', '$state',
function($scope, $rootScope, $resource, $state) {
$scope.submitOwnerFindForm = function() {
var destUrl = '/petclinic/owner/list?lastName='
if(angular.isDefined($scope.ownerFindForm)) {
destUrl += $scope.ownerFindForm.lastName;
}
angular.module('controllers').controller('ownerSearchController', ['$scope', '$state',
function($scope, $state) {
$scope.ownerSearchForm = {};
// form always needs to be initialised
// otherwise we can't read $scope.ownerSearchForm.lastName
var ownerResource = $resource(destUrl);
$rootScope.owners = ownerResource.query();
$state.go('app.ownerlist'); //updating URL in address bar
}}]);
$scope.submitOwnerSearchForm = function() {
var lastNameValue;
$state.go('app.ownerlist', {lastName: $scope.ownerSearchForm.lastName});
}}]);
/*
* Owners List
*/
angular.module('controllers').controller('ownerListController', ['$scope', '$rootScope',
function($scope, $rootScope, $location) {
if ($rootScope.owners!=null){
$scope.ownerList = $rootScope.owners;
}
}]);
angular.module('controllers').controller('ownerListController', ['$scope', '$resource', '$stateParams',
function($scope, $resource, $stateParams) {
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)
......@@ -46,6 +47,8 @@ function loadOwner($scope, $resource, $stateParams) {
angular.module('controllers').controller('ownerFormController', ['$scope', '$resource', '$http', '$stateParams', '$state',
function($scope, $resource, $http, $stateParams, $state) {
scope.submitOwnerForm = {};
$scope.submitOwnerForm = function() {
var form = $scope.owner;
......
<h2>Find Owners</h2>
<form class="form-horizontal" id="ownerFindForm" data-ng-controller="ownerSearchController">
<h2>Find Ownersss</h2>
<form class="form-horizontal" ng-controller="ownerSearchController">
<fieldset>
<div class="control-group" id="lastName">
<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 class="form-actions">
<button type="submit" ng-click="submitOwnerFindForm()">Find Owner</button>
<button type="submit" ng-click="submitOwnerSearchForm()">Find Ownerss</button>
</div>
</fieldset>
</form>
<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