<div ng-app="formApp">
<div ui-view />
</div>
<script type="text/ng-template" id="form/step1.html">
Step 1 -
What animal do you prefer ?
<button ng-click="
formCtrl.selectAnimal('doge');
">
Doge
</button>
<button ng-click="
formCtrl.selectAnimal('cate');
">
Cate
</button>
</script>
<script type="text/ng-template" id="form/step2.html">
Step 2 -
What color do you like your {{formCtrl.formRegistry.animal}}?
<button ng-click="
formCtrl.selectColor('white');
">
White
</button>
<button ng-click="
formCtrl.selectColor('black');
">
Black
</button>
</script>
<script type="text/ng-template" id="form/step3.html">
Step 3 -
{{formCtrl.result()}}
</script>
var formApp = angular.module('formApp', ["ui.router"]);
formApp.config(function($stateProvider, $urlRouterProvider){
$stateProvider
.state('form', {
abstract: true,
url: '',
template: '<ui-view/>',
controller: 'formController as formCtrl',
})
.state('form.step1', {
url: '/step1',
templateUrl: "form/step1.html",
})
.state('form.step2', {
url: '/step2',
templateUrl: "form/step2.html",
})
.state('form.step3', {
url: '/step3',
templateUrl: "form/step3.html",
})
;
$urlRouterProvider.otherwise('/step1');
});
formApp.service('formRegistry', function(){
this.animal = undefined;
this.color = undefined;
});
formApp
.controller('formController', function($state, formRegistry){
this.selectAnimal= function(animal){
formRegistry.animal = animal;
$state.go('form.step2');
}
this.formRegistry = formRegistry;
this.selectColor= function(color){
formRegistry.color = color;
$state.go('form.step3');
}
this.result = function(){
if(formRegistry.animal === 'doge'){
if (formRegistry.color === 'white'){
return 'wow. white doge. such noble. so lithgside. much puer. wow'
}
return 'wow. black doge. such scary. many darkness. so scare. wow'
}
if (formRegistry.color === 'white'){
return 'white cate wisdom - “In the middle of a world that has always been a bit mad, a cat walks with confidence.” '
}
return 'Black cate. Pernicious. 13. Bad luck';
}
});
This Pen doesn't use any external CSS resources.