发布到templateUrl

I have created a dynamic route in AngularJS which allows all routes to be processed via a single PHP file. The reason I do this is because, I don't like how you can navigate to the raw templateUrl and see an unstyled partial page.

Before I learnt Angular, I had Ajax requests POSTing to the PHP file, but I can't seem to do this with Angular. I have made it so the requests go to /router.php?page=XX... but even still, this URL now has to accept GET requests.

Can I not make it so that the templateUrl is loaded via a POST request?

The route (no pun intended) that I would go with this is using the template property instead of templateUrl.

The docs have this to say about $routeProvider :

template – {string=|function()=} – html template as a string or a function that returns an html template as a string which should be used by ngView or ngInclude directives. This property takes precedence over templateUrl.

As opposed to templateUrl:

templateUrl – {string=|function()=} – path or function that returns a path to an html template that should be used by ngView.

You can see that dynamically forming the templateUrl with a function would only benefit you with a url string, still performing a GET request. The template property could fetch the actual html of the template using whatever means necessary.

Using this approach, you should be able to pass the template property a function that either calls a service that performs the POST operation or injects $http directly. The only part I'm not sure about is how the template property would treat a promise from the http request before the data is returned.

I hope this helps you!