AngularJS如何从ng-view的模板中钩入head标签
AngularJS how to hook into the head tag from the template of the ng-view
我习惯使用Laravel的Blade模板引擎,但现在我正在学习在前端使用AngularJS,我已经放弃了Blade。
我试图包括一些页面特定的脚本标签,我不想包括在我的主<ng-view></ng-view>
页
<html>
<head>
// want to be able to inject stuff here from the ng-view's template
</head>
<body>
<ng-view></ng-view>
<body>
</html>
并且通常使用laravel,我可以在head标签中包含@yield
,以便稍后在我的模板中我可以执行@section
来访问head标签。我可以用Angular做一些类似的事情吗?
试试
<html ng-app="myApp">
<head>
<script ng-repeat="script in headScripts" ng-src="script"/>
</head>
<body>
<ng-view>
<div ng-click="addHeadScript('/scripts/new.js');"></div>
</ng-view>
<body>
</html>
var app = angular.module('myApp');
app.run('$rootScope', function($rootScope){
$rootScope.headScripts = [];
$rootScope.addHeadScript = function(src){
$rootScope.headScripts.push(src);
}
});
相关文章:
- 在<页眉>标签
- Ckeditor-plugin:插入虚假元素add不情愿<p>标签前后
- iframe正在添加标签,需要删除它们
- 如何自动调整标签的高度以适应内容
- Jquery标签插件粘贴问题
- Twitter引导程序Typeahead-Id&标签
- Highcharts-如何在自定义格式化程序中获得默认的y轴标签格式化程序
- 使用 jQuery 将 CSS 添加到正文中的 head 标签
- 有没有办法将 css 文件或 javascript 文件动态注入 HTML 文档的 head 标签中
- 在 head 标签中动态添加
- 是否有必要在ajax请求的页面中编写标题,html,head标签
- 在javascript的head标签内编写脚本是最好的选择,为什么
- AngularJS如何从ng-view的模板中钩入head标签
- 在PageMod (Firefox插件SDK)的HEAD标签的顶部插入一个脚本
- 为什么require.js进入head标签
- 在head标签内插入字符串
- 使用 JavaScript 删除 head 标签内的 noscript 标签
- 为什么 head>;标签和其他一些不被认为是HTML的
标签
- joomla的Head标签中的Javascript
- 访问加载在html head标签中的mustache模板