我试图使用ng-include将html文件包含到另一个html中。跟随this没有运气,可能是由于webpack版本差异。
尝试在ng-include
中查找文件时出现404错误的package.json
"devDependencies": {
..//other dependencies
"required-loader": "^1.3.15",
"extract-text-webpack-plugin": "^3.0.1",
"file-loader": "^1.1.5",
"html-loader": "^0.5.1",
"html-webpack-plugin": "^2.30.1",
..//other dependencies
}
index.js(应用程序的入口点)
import angular from 'angular'
import uirouter from 'angular-ui-router'
import routes from './routes'
//trying to require all files inside views/all dir/all html files
//@require "../views/**/*.html"
angular.module('app', [uirouter])
.config(routes)
.controller('LoginCtrl', function() {})
index.html文件,需要包含navbar.html文件
index.html
views
--> common
--> navbar.html
的index.html
<div ng-include="'navbar.html'">
答案 0 :(得分:1)
我找到了解决此问题的更好方法,而不是使用ng-include。我为导航栏创建了一个角度组件,并将其注入到html中。
<navbar></navbar>
在组件定义中,我使用import语句来调用html模板
import navbarTemplate from '../PATH';
angular.module('app')
.component('navbar', {
template: navbarTemplate,
...
});