您的位置:首页 > Web前端 > AngularJS

angularJS自定义指令模板替换

2015-05-10 10:57 260 查看
<html>
<head>
<meta charset="utf-8"/>
<title></title>
</head>
<body ng-app="components">
<myelement>
<h1>哈哈</h1>
</myelement>
</body>
<script src="angular.js"></script>
<script>
var app= angular.module('components', []);
app.directive('myelement', function() {
return {
restrict: 'AE',//自定义属性和Dom节点
transclude: true,//将自定义指令内部原有的节点保留(这里注意,自定义指令中的内容在模板中必须有父节点)
scope: {},
templateUrl:"templates/templateOther.html",
replace: true,//全部替换
link:function(scope,element,attr){
element.bind("click",function(){
alert(1);
})
}
};
});
</script>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: