使用ngInclude包含html文件(Including html files using ngInclude)

编程入门 行业动态 更新时间:2024-10-03 04:43:58
使用ngInclude包含html文件(Including html files using ngInclude)

我正在尝试使用ng-include将html文件包含到另一个html中。 跟随这个没有运气,也许由于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() {})

需要包含navbar.html文件的index.html文件

index.html views --> common --> navbar.html

的index.html

<div ng-include="'navbar.html'">

I'm trying to include an html file in to another html using ng-include. Followed this with no luck, maybe due to webpack version differences.

404 errors trying to find the file in the ng-include

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 (entry point to app)

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 file that needs to include navbar.html file

index.html views --> common --> navbar.html

index.html

<div ng-include="'navbar.html'">

最满意答案

我发现了一个更好的方法来解决这个问题,而不是使用ng-include。 我为navbar创建了一个角度组件并将其注入到html中。

<navbar></navbar>

在组件定义中,我使用import语句来调用html模板

import navbarTemplate from '../PATH'; angular.module('app') .component('navbar', { template: navbarTemplate, ... });

I found a better approach to solving this problem instead of using ng-include. I created an angular component for navbar and injected that in to html.

<navbar></navbar>

in the component definition, I use import statement to call the html template

import navbarTemplate from '../PATH'; angular.module('app') .component('navbar', { template: navbarTemplate, ... });

更多推荐

html,ng-include,index,trying,file,电脑培训,计算机培训,IT培训"/> <meta name=&

本文发布于:2023-07-09 10:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085584.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   html   ngInclude   Including   files

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!