I am using $stateProvider to set-up my states like so:
constructor($stateProvider, $urlRouterProvider, $locationProvider) {
$stateProvider.
state("something", {
url: "/index.html"
})
// many more
}
I am not using $urlRouterProvider.otherwise('default-something');, so when I type /invalidstate, I was expecting a 404. Instead, I'm getting a 200 response.
What I'm trying to do is set up a 404 interceptor, but in order for me to intercept, I have to get a 404. I can't fathom for the life of me why a state that's not handled would result in a 200.
You are getting a 200 response because so far as the server is concerned, that is a valid route.
Related
Here is my route:
.state('payment-paytm', {
parent: 'app',
url: '/pricing/paytm_update',
component: 'pricing',
resolve: {
data: function (PricingService,$stateParams) {
return PricingService.paytm_update_status($stateParams);
}
}
});
this route is not accepting post request coming from paytm call back.
paramList["CALLBACK_URL"] = "http://localhost:9000/pricing/paytm_update"
this is the url we configured in paytm, this is responding correctly but this post request am not able to handle in my angular.
very first thing,paytm not support REST,so after you are making transaction,you have handle on backend url ( "http://localhost:9000/pricing/paytm_update").from there,use res.redirect("angular url/with paymentid").then by using that id you can display transaction details from your angular frontend
I think angular will not be able to capture the post request coming from paytm.
you have to catch it from the server side language and post it to angular route.
for post parameters you could include it in the url ($stateParams) and then you could get the parameters in your angular controller.
I have a login view, on submission of user credentials , a service will called with a post request ,here I am getting the 404, I need display a meaning full message for 404 error on the login view, which I am not able to,
could some one help me and suggest a workaround for this?
Below are the routes:
$stateProvider
.**state("/",{
url:'/',
templateUrl:'./resources/js/baseapp/ContactLogin/views/login.html',
controller:'contactLoginCtrl'
})**
$urlRouterProvider.otherwise("/");
Below is the service
var indata = { "password": pword, "username":uname };
var req ={
method: 'POST',
url: 'http://localhost:8083/spring2/login',
data: indata
}
$http(req).then(function (response) {
console.log(response);
// *here I am getting the 404, need to redirecr from serivce to view with error displayed on view*
}, function (error) {
console.log(error)
});
}
}
I saw few post regarding this on stack overflow they are displaying a complete page of 404 error, I don't need that, I need the same view on top it a meaning full message.
I have to redirect to templateUrl with an additional meaning full message, this message should be removed automatically if again a resubmisssion happens from the view.
If you are using a service/factory to make the login call, then you can get the response object at controller using promise .and there you can show the response object in view.
Getting 404 error when I do refresh on angular page. HTTP Status 404 - /product/P12345
Below is the my route configuration
MyApp.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/product', {
templateUrl: 'components/product/product.html',
controller: 'ProductCtrl'
});
First time i'm hitting url as http://localhost:8080/index.html#/product/P12345 In the browser url get converted into http://localhost:8080/product/P12345
when i click on refresh button getting 404 error.
Not sure what causing the issue, any help is greatly appreciated.
Using ui-router in Angularjs users can accesses resources from my DB with a unique code in the URL like this:
http://example.com/abc123
with the state:
.state('show', {
url: '/:resourceID',
templateUrl: '/views/resource.html',
controller: 'ResourceController'
})
However, I'm not sure how to render the 404.html when a resource isn't found in the DB. At the moment I am returning a 404 error from Expressjs and I have an interceptor that then redirects using:
//detect 404 and redirect url
$window.location.href = "/error/404";
but this isn't ideal - you have to wait for the redirect and the URL changes.
How can I show a static 404.html and not affect the URL in the browser?
It seems this is working solution that shows how to work with $httpBacked http://jsfiddle.net/EgMpe/8/
But for my case:
routes
app.config(['$routeProvider', function($routeProvider) { $routeProvider.
when('/', {templateUrl: 'partials/user-list.html'}).
...
faked service:
app.run(function($httpBackend) {
var users = [{"id":1,"name":"bob","email":"bob#bobs.com"}, {"id":2,"name":"bob2","email":"bob2#bobs.com"}]
$httpBackend.whenGET('/rest/users').respond(function(method,url,data) {
console.log("Getting users");
return [200, users, {}];
});
});
..
real service:
services.factory('Users', function($resource){
return $resource('/rest/users', {}, {
get: {method: 'GET', isArray:true}
});
});
I have error when go to my "/" route that redirects me to user-list.html page:
Error: Unexpected request: GET partials/user-list.html No more request
expected
at $httpBackend .../mysite/public/angular/libs/angular-1.2.0/angular-mocks.js:1060:9)
Question1: Does httpBackend prevent doing any other http request?
I tried to use passThrough method to let http hit real server side:
$httpBackend.whenGET(/^\/mysite\//).passThrough();
But this does not help.
Using $httpBackend you have to specify in advance all request you are going to perform. Maybe this short excerpt from Mastering Web Application Development with AngularJS will clarify why:
The verifyNoOutstandingExpectation method verifies that all the expected
calls were made ($http methods invoked and responses flushed), while the
verifyNoOutstandingRequest call makes sure that code under test didn't trigger
any unexpected XHR calls. Using those two methods we can make sure that the code
under the test invokes all the expected methods and only the expected ones.
Ah.. Sorry I just was wrong with my RegEx:
if type this $httpBackend.whenGET(/partials/).passThrough();
Then all start working.
So, I got my lesson: don't forget to put: passThrough(); with right RegEx.