AngularJS + Karma + Ng-html2js => Failed to instantiate module …html

后端 未结 4 891
深忆病人
深忆病人 2021-02-02 09:28

I can\'t make Karma working for directives that have external templates.

Here is my karma configuration file :

pr         


        
4条回答
  •  梦谈多话
    2021-02-02 10:24

    The problem may be that relative paths specified in file section get expanded to full ones.

    Something like directives/loading/templates/loading.html => /home/joe/project/angular-app/directives/loading/templates/loading.html

    ... and then, templates get registered with theirs full paths.

    The solution is to configure the ng-html2js preprocessor to remove the absolute part of the template paths. For instance, in the karma.conf.js file add the stripPrefix directive like this :

    ngHtml2JsPreprocessor: {
        // strip this from the file path
        stripPrefix: '.*/project/angular-app/'
        prependPrefix: '/app/'
    }
    

    Note that stripPrefix is a regexp.

提交回复
热议问题