weixin_33725722 2015-10-04 03:37 采纳率: 0%
浏览 10

发布到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?

  • 写回答

1条回答 默认 最新

  • H_MZ 2015-10-04 04:34
    关注

    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!

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题