I want to create multi step form using angularjs.
Here is the code:
(function () {
"use strict";
angular.module("gameManagement", ["ui.router", "ngAnimate", "ngResource", "toaster"])
.config(["$stateProvider", "$urlRouterProvider", function ($stateProvider, $urlRouterPorvider) {
$urlRouterPorvider.otherwise("/Game/Home");
$stateProvider
.state("Home", {
url: "/Game/Home",
templateUrl: "/app/Game/GameView.html",
controller: "GameController as vm"
});
$stateProvider
.state("Log", {
url: "/Game/Log",
templateUrl: "/app/Log/GameLogView.html",
controller: "GameLogController as vm"
});
$stateProvider
.state("MultiStepForm", {
url: "/Game/MuiltyStepForm",
templateUrl: "/app/MultiStepForm/MuiltyStepForm.html"
});
$stateProvider
.state("MultiStepForm.view", {
url: "/Game/MuiltyStepForm/view",
templateUrl: "/app/MultiStepForm/MuiltyStepForm.html"
})
.state('MultiStepForm.view.step1', {
url: '/step1',
templateUrl: '/app/MultiStepForm/FormStep1.html'
})
.state('MultiStepForm.view.step2', {
url: '/step2',
templateUrl: '/app/MultiStepForm/FormStep2.html'
})
.state('MultiStepForm.view.step3', {
url: '/step3',
templateUrl: '/app/MultiStepForm/FormStep3.html'
})
}]);
})();
I get this error when I try to move to state MultiStepForm.view.step2
Error: Could not resolve '.MultiStepForm.view.step2' from state 'MultiStepForm.view'
Any idea why I get the error?
And can I create nested state inside nested state?
Hi this is because you are using nested states so in your example
.state('MultiStepForm.view.step1', {
url: '/step1',
templateUrl: '/app/MultiStepForm/FormStep1.html'
})
.state('MultiStepForm.view.step2', {
url: '/step2',
templateUrl: '/app/MultiStepForm/FormStep2.html'
})
.state('MultiStepForm.view.step3', {
url: '/step3',
templateUrl: '/app/MultiStepForm/FormStep3.html'
})
step2 inherits from step1 and not from multistepform.view
I think you should be able to fix it by doing this :
.state('MultiStepForm.view.step1', {
url: '/step1',
templateUrl: '/app/MultiStepForm/FormStep1.html'
})
.state('MultiStepForm.view.step2', {
url: '/step2',
parent: MultiStepForm.view,
templateUrl: '/app/MultiStepForm/FormStep2.html'
})
.state('MultiStepForm.view.step3', {
url: '/step3',
parent: MultiStepForm.view,
templateUrl: '/app/MultiStepForm/FormStep3.html'
})
check out this url for more info about nested states nested views in angular
Related
Here below is my URL
localhost:9000/index.html#!/app/apis/1066/general.
If I change value of param to 1067 it should update API(s) general information based on 1067.
But instead URL is set back to param value 1066 instantly and the page is not refreshed.
Here is my route:
$ocLazyLoadProvider.config({
debug:false,
events:true
});
$urlRouterProvider.otherwise('/app/welcome');
$stateProvider
.state('app', {
abstract:true,
url:'/app',
templateUrl: 'views/dashboard/main.html'
})
.state('app.home', {
url: '',
templateUrl: 'views/dashboard/home.html',
controller: 'MainCtrl'
})
.state('app.api', {
url: '/apis',
controller: 'apiCtrl',
templateUrl: 'views/dashboard/apis/index.html'
})
.state('app.addApi', {
url: '/apis/add',
controller: 'apiCtrl',
templateUrl: 'views/dashboard/apis/createApi.html'
})
.state('app.apis', {
url: "/apis/:id",
templateUrl:"views/dashboard/apisMain/updateApis.html",
controller: "updateApisCtrl",
resolve:{
apiData :function ($stateParams, proxyService) {
return proxyService.api($stateParams.id);
}
}
})
.state('app.apis.general', {
url: "/general",
templateUrl: "views/dashboard/general/updateGeneral.html",
controller: "updateGeneralCtrl"
})
I can provide more information if needed. I'm using angularjs 1.7
It might be so that the stateprovider does not consider new url props in it's cache-key.
Try to disable the cache on the state and see if it helps
.state('app.apis', {
cache: false,
url: "/apis/:id",
templateUrl:"views/dashboard/apisMain/updateApis.html",
controller: "updateApisCtrl",
resolve:{
apiData :function ($stateParams, proxyService) {
return proxyService.api($stateParams.id);
}
}
You miss param ID in path config state general, Please try change it:
state('app.apis.general', {
url: "/general",
templateUrl: "views/dashboard/general/updateGeneral.html",
controller: "updateGeneralCtrl"
})
>>>change
state('app.apis.general', {
url: "/:id/general",
templateUrl: "views/dashboard/general/updateGeneral.html",
controller: "updateGeneralCtrl"
})
I am trying to develop an app using Angular 1.4.(Refer below image). I need suggestions on below
What is the best way to develop home Page in this. Should I use <ui-view>(UI routing) to creates the 8 states or should I use 8 different custom directives to tabs(tab1, tab2, tab3, etc...)
Can my application has both routeprovider and stateprovider together in config file.(Another post from Stackoverflow)
--------------------------------------------------------------------------->
My view/idea for developing this---->
will be using ng-view to load the pages(home, nav2, nav3, etc)
will be using ui-view to load the tabs/panel inside home page(tab1, tab2, tab3, etc)
Using Both ng-view and ui-view does not show any results in the file. i.e, App crashes.. So I have moved to ui-view to display all the states.
Below is the code which works fine.
Tutorial
.config(function($urlRouterProvider, $stateProvider) {
$urlRouterProvider.otherwise('/home');
$stateProvider
.state("home", {
url:"/home",
views:{
"":{
templateUrl: "views/home.html"
},
"profile#home":{
templateUrl: "views/home/profile.html"
},
"companyAnnouncement#home":{
templateUrl: "views/home/company-announcement.html"
},
"leaveBalance#home":{
templateUrl: "views/home/leave-balance.html"
},
"leaveDetails#home":{
templateUrl: "views/home/leave-details.html"
},
"attendenceDetails#home":{
templateUrl: "views/home/attendence-details.html"
},
"holidayList#home":{
templateUrl: "views/home/holiday-list.html"
},
"queryStatus#home":{
templateUrl: "views/home/query-status.html"
},
"payrolQueryStatus#home":{
templateUrl: "views/home/payrol-query-status.html"
}
}//views ends here
})
.state("login", {
url: "/login",
templateUrl: "views/login.html"
})
.state("selfService", {
url:"/self-service",
views:{
"":{
templateUrl: "views/self-service.html"
}
}
})
.state("edirectory", {
url: "/edirectory",
templateUrl: "views/edirectory.html",
controller: 'edirectoryController',
controllerAs: 'edirectoryCtrl',
resolve: {
employeeList: function (edirectoryService) {
return edirectoryService.getAllEmployees();
}
}
})
.state("myLeave", {
url: "/my-leave",
templateUrl: "views/my-leave.html"
})
.state("attendence", {
url: "/attendence",
templateUrl: "views/attendence.html"
})
.state("compOffRequest", {
url: "/comp-off-request",
templateUrl: "views/comp-off-request.html"
})
.state("raiseQuery", {
url: "/raise-query",
templateUrl: "views/raise-query.html"
})
.state("eacademy", {
url: "/eacademy",
templateUrl: "views/eacademy.html"
})
.state("downloads", {
url: "/downloads",
templateUrl: "views/downloads.html"
});
});
I have a main view and a submain view. In submain, I agian have some subviews but these are suppose to be loaded dynamically i.e Round1,Round2,Round3.... is coming from dynamic value It may have 5 rounds or 4 or 3... How can I load those states dynamically ?
angular
.module('myApp', ['ngResource', 'ngRoute', 'ui.router'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('main', {
url: '/main',
templateUrl: 'views/mainView.html',
controller: 'mainCtrl'
})
.state('main.submain', {
url: '/sub_main',
templateUrl: 'views/subMainView.html',
controller: 'subMainCtrl'
})
.state('main.submain.Round1', {
url: '/Round_One',
templateUrl: 'views/subView.html',
})
.state('main.submain.Round2', {
url: '/Round_Two',
templateUrl: 'views/subView.html'
})
.state('main.submain.Round3', {
url: '/Round_Three',
templateUrl: 'views/subView.html'
})
.state('main.submain.Round4', {
url: '/Round_Four',
templateUrl: 'views/subView.html'
})
.state('main.submain.Round5', {
url: '/Overall_Feedback',
templateUrl: 'views/Round5View.html'
})
$urlRouterProvider.otherwise('/login');
});
Please refer to the this Stack overflow question. This way you can add state to your $stateprovider dynamically
Hi below is my code for urlRouterProvider otherwise.
.config(function config($urlRouterProvider, $stateProvider) {
$urlRouterProvider.otherwise('/invalid');
$stateProvider.state('view', {
url: '/view?{businessId:^[0-9]{1,20}$}',
templateUrl: 'view/view.tpl.html',
controller: 'ViewCtrl',
controllerAs: 'vm'
})
.state('otherwise', {
url: '/invalid',
templateUrl: 'view/view.error.tpl.html'
});
})
This is what i am expecting:
1. if i go to view?businessId=12345 it should load the page without any issues
2. if i go to view?businessId=abcd it should re-direct it to the view.error.tpl.html
But instead, it does nothing if i enter the invalid url.
I reffered to this post for help but none of the options really work Otherwise on StateProvider
you can try this, without using the otherwise function:
$stateProvider.state('view', {
url: '/view?{businessId:^[0-9]{1,20}$}',
templateUrl: 'view/view.tpl.html',
controller: 'ViewCtrl',
controllerAs: 'vm'
})
.state('otherwise', {
url: '*path',
templateUrl: 'view/view.error.tpl.html'
});
Try this
.config(function ($urlRouterProvider, $stateProvider) {
$stateProvider.state('view', {
url: '/view?{businessId:^[0-9]{1,20}$}',
templateUrl: 'view/view.tpl.html',
controller: 'ViewCtrl',
controllerAs: 'vm'
})
.state('otherwise', {
url: '*path',
templateUrl: 'view/view.error.tpl.html'
});
})
Hello when i have this states defined:
.state('locations', {
url: '/locations',
templateUrl: '/templates/locations/index.html',
controller: 'LocationsCtrl'
})
.state('locations.show', {
url: '/{location_id}',
templateUrl: '/templates/locations/show.html'
});
How can i have /templates/locations/index.html to show for example a list of all locations,
but templates/locations/show.html to show a view of the location, but not nested inside the view of index.html. Basically i want the routes nested, but not the views.
I just worked on an example similar to yours
.state('overview', {
url: '/all',
templateUrl: '_/partial/overview/all.html',
controller: 'homeCtrl'
})
.state('places', {
url: '/:id/place',
templateUrl: '_/partial/details/detail-place.html',
controller: function($scope, $stateParams) {
$scope.path = $scope.paths[$stateParams.id];
}
})
In your case
.state('locations', {
url: '/locations',
templateUrl: '/templates/locations/index.html',
controller: 'LocationsCtrl'
})
.state('show', {
url: '/{location_id}',
templateUrl: '/templates/locations/show.html'
});
That means the show state shouldn't be nested under locations.