Solution to: "Origin is not allowed by Access-Control-Allow-Origin." with AngularJS and ngResource ($resource)
1 min read
I just spent way to much time trying to figure out why I kept getting this error:

- Origin is not allowed by Access-Control-Allow-Origin.*
Here’s the code snippet:
var resource = $resource('http://localhost:17482/api/x/:id', { id: '@id' });
```text
After a lot of digging I discovered that you need to escape the port when using $resource. [Here’s the issue thread on github](https://github.com/angular/angular.js/issues/1243)
```js
var resource = $resource('http://localhost\\:17482/api/x/:id', { id: '@id' });Add those two slashes before the port and the error goes away.
Hope I just saved you hours of pain.
Jon
Share:
Share on LinkedIn
Quick Share: Your custom post text has been copied to your clipboard! Click the button below to open LinkedIn's share dialog, then paste it.
💡 Tip: LinkedIn will open in a new tab. Use Ctrl+V (or Cmd+V on Mac) to paste your text.
Note: LinkedIn will show the article preview. You can add your custom text above it.