Hello I am trying to implement a multistage form using Tab of angularJS. I don't want to use route in this application.
app.controller('createProjectController', ['$scope', 'resourceProject', function ($scope, resourceProject) {
this.tab = 1;
this.setTab = function (newValue) {
this.tab = newValue;
};
this.isSet = function (tabName) {
return this.tab === tabName;
};
$scope.project = {};
$scope.postProject = function () {
// console.log("Post Here");
// $scope.project.Id = null;
resourceProject.postEvent().save($scope.project)
.$promise.then(
function (response) {
console.log("Saved");
//console.log(response);
$scope.project = response;
//Does not recognize this action
console.log(this.tab);
// Not Working
this.tab = 2;
// Not working setTab(2);
},
function (error) {
console.log("It was broken !");
});
}
}]);
Then in HTML I am doing following:
<section class="tab" ng-controller="createProjectController as tab">
<ul class="nav nav-pills">
<li ng-class="{ active: tab.isSet(1) }">
<a href ng-click="tab.setTab(1)">Project Information</a>
</li>
<li ng-class="{ active: tab.isSet(2) }">
<a href ng-click="tab.setTab(2)">Further Information</a>
</li>
<li ng-class="{ active: tab.isSet(3) }">
<a href ng-click="tab.setTab(3)">Groups</a>
</li>
<li ng-class="{ active: tab.isSet(4) }">
<a href ng-click="tab.setTab(4)">Chart</a>
</li>
<li ng-class="{ active: tab.isSet(5) }">
<a href ng-click="tab.setTab(5)">Specification</a>
</li>
</ul>
@*First Tab Project Info*@
<div ng-show="tab.isSet(1)">
<h4>General Project Information</h4>
<div>.....General form...</div>
</div>
<div ng-show="tab.isSet(2)">
<h4>Further Information</h4>
<blockquote>And so on </blockquote>
</div>
// Similarly other tabs....
The problem is: Tabs are changing nicely in on click(ng-click) event. But As I want to change the tabs on success of post event in controller function, Its not working :(
Looking forward to get some support. P.S. I am new in AngularJS.