angular 1.5组件模板webpack require()导致错误

时间:2021-07-15 20:30:09

I'm using angular 1.5.3 with es6, webpack and jade templates.

我使用角度1.5.3与es6,webpack和玉石模板。

Everything works as expected except for the component's templates.

除组件的模板外,一切都按预期工作。

This works

var cmpnt = {
    template: '<div>test</div>'
}

This also works (when I manually create the html file)

这也有效(当我手动创建html文件时)

var cmpnt = {
    template: require('./component.html')
}

This does NOT work

这不起作用

var cmpnt = {
    template: require('./component.jade')
}

In the browser console, I get

在浏览器控制台中,我得到了

Error: [$injector:unpr] Unknown provider: localsProvider <- locals

错误:[$ injector:unpr]未知提供者:localsProvider < - locals

The .jade file exists, and I'm using require('./template.jade') in many other places of the app without problems.

.jade文件存在,我在应用程序的许多其他地方使用require('./ template.jade')没有问题。

Any ideas? Any more info I can provide?

有任何想法吗?我可以提供更多信息吗?

1 个解决方案

#1


9  

jade-loader returns a function. You cannot to pass that function to template, you must to invoke the function before pass it

jade-loader返回一个函数。您不能将该函数传递给模板,您必须在传递之前调用该函数

var cmpnt = {
    template: require('./component.jade')();
}

note the call of function after require

请注意require之后的函数调用

#1


9  

jade-loader returns a function. You cannot to pass that function to template, you must to invoke the function before pass it

jade-loader返回一个函数。您不能将该函数传递给模板,您必须在传递之前调用该函数

var cmpnt = {
    template: require('./component.jade')();
}

note the call of function after require

请注意require之后的函数调用