在指令中使用模板网址会冻结应用程序
Using templateUrl in directive freezes app
我有一个MEANstack应用程序,它的行为非常奇怪。使用 templateUrl 创建指令会冻结应用程序。相同的指令仅使用带有模板的 html 代码。
仪表板.html:
<h3>Recent</h3>
<div my-callout></div>
dashboard.controller.js:
.directive('myCallout', function(){
return {
templateUrl:'myCallout.html'
};
})
myCallout.html:
<div>
<p>fdsfs</p>
</div>
这有效:
.directive('myCallout', function(){
return {
template:' <p> mhgfhut </p>'
};
})
;
你的指令对我来说很好用:
~/angular_js_projects/9app$ tree
.
├── app.css
├── app.js
├── bootstrap
<snip>
├── index.html
└── myCallout.html
应用.js:
var app = angular.module('myApp', []);
app.directive('myCallout', function() {
return {
templateUrl: 'myCallout.html'
}
});
myCallout.html:
<div>myCallout.html</div>
索引.html:
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>AngularJS</title>
<meta charset="UTF-8"> <!-- For html5 (default is UTF-8) -->
<meta name="viewport" content="width=device-width, initial-scale=1"> <!-- For Bootstrap -->
<!-- Bootstrap CSS with glyphicon fonts in bootstrap/fonts/ -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<h3>Recent</h3>
<div my-callout></div>
<!-- Angular -->
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<!-- App Script -->
<script src="app.js"></script>
</body>
</html>
使用此目录结构:
~/angular_js_projects/9app$ tree
.
├── app.css
├── app.js
├── bootstrap
<snip>
├── index.html
└── templates
└── myCallout.html
然后 app.js 看起来像这样:
var app = angular.module('myApp', []);
app.directive('myCallout', function() {
return {
templateUrl: 'templates/myCallout.html'
}
});
相关文章:
- Canvas Html5绘图应用程序,移动画布会导致重大问题
- Emberjs应用程序加载在除Index之外的所有路由上
- 使用电话间隙在Android应用程序中显示SQL Lite的数据
- 在AngularJS应用程序中使用封装指令和路由的推荐方式是什么
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- angular 1.5应用程序中的导航栏
- 在Web应用程序中使用Highcharts javascript
- angularjs+rails应用程序中未显示模板
- 交互和目标保存冻结应用程序
- 当调用JS函数具有alert()时,应用程序将被冻结
- Cordova应用程序在安卓系统上运行,但线程似乎在ios上冻结了;“由于页面加载而重置插件”;
- 基于Ionic和AngularJS的模态对话框导致应用程序冻结
- 执行流星重置时,登录用户的应用程序页面冻结
- 在指令中使用模板网址会冻结应用程序
- iPad 网络应用程序在 Safari 中打开链接后冻结
- 应用程序打开后冻结,Phonegap警报不起作用
- 反应本机相机在通过导航器打开 2 次时冻结应用程序
- PhantomJS.在我的rails应用程序中尝试屏幕捕获页面时Rb冻结
- Cordova应用程序在启动屏幕冻结
- NodeJS:如果冻结对象,应用程序会运行得更快吗