AngularJS指令替换内容

原创
2016/07/27 18:12
阅读数 80

transclude.html

<!doctype html>
<html ng-app="MyModule">
	<head>
		<meta charset="utf-8">
	</head>
	<body>
		<hello>
			<div>这里是指令内部的内容。</div>
		</hello>
	</body>
	<script src="framework/angular-1.3.0.14/angular.js"></script>
	<script src="transclude.js"></script>
</html>

transclude.js

var myModule = angular.module("MyModule", []);
myModule.directive("hello", function() {
    return {
		restrict: "AE",
		transclude: true,
    	template:"<div>Hello everyone!<div ng-transclude></div></div>"
        //templateUrl: 'hello.html',引用html文件的地址
		//hello指令内容替换位置ng-transclude
    }
});

效果

输入图片说明

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部