jeudi 26 mars 2015

Foundation for Apps, how to change view on form submit?

Excited to find out about Foundation for Apps coming bundled with AngularJS, I took this as an excuse to start learning AngularJS. I try to recreate parts of an old web app to see what's possible with this new framework. And I hit a roadblock:


One of the views is a search form. On "submit" it should slide away and the "Result" view should slide in. Now, switching those views using <a ui-sref=""> (like in a navigation menu) works fine. But how to trigger this - and have the SearchField InputValue passed on as parameter - on formSubmit?


Following the example given in http://ift.tt/1ykfMbW I created a controller that is attached to the form like this.


<form ng-controller="StaffSearchController" ng-submit="doSearch()" >



angular.module('application').controller('StaffSearchController', StaffSearchController);
StaffSearchController.$inject = ['$scope', '$stateParams', '$state', '$controller'];
function StaffSearchController($scope, $stateParams, $state, $controller) {
angular.extend(this, $controller('DefaultController', {$scope: $scope, $stateParams: $stateParams, $state: $state }));
console.info("StaffSearchController");
$scope.searchTerm = "search me";
$scope.doSearch = function(){
console.log("doSearch");
};
}


The doSearch() gets called. but what do do from there to switch to the next view?


Aucun commentaire:

Enregistrer un commentaire