modifying ng-include directive

后端 未结 4 1876
情歌与酒
情歌与酒 2021-01-23 05:37

if I host an angular app at some custom location e.g. http://localhost/collosys then i have to change all the ng-include to have \"/collosys/\" for all the address

4条回答
  •  礼貌的吻别
    2021-01-23 05:56

    I solved this issue using $httpProvider.interceptors. The following prepends 'myAppDirectory' to ALL requests.

    $httpProvider.interceptors.push(function($q) {
        return {
         'request': function(config) {
             config.url = 'myAppDirectory/'+config.url;
             return config;
          },
        };
      });
    

    A regular ng-include, such as:

    Will load myAppDirectory/user/info.html

    You probably want to make some exceptions. In my case:

      $httpProvider.interceptors.push(function() {
        return {
         'request': function(config) {
             // ignore api calls and ui-bootstrap templates.
             if (config.url.indexOf('api')==-1 && config.url.indexOf('template')==-1) {
               config.url = 'myAppDirectory/'+config.url;
             }
             return config;
          },
        };
      });
    

提交回复
热议问题