angularJs利用Directive实现View复用

Angularjs的MVC是借助于$scope实现的。

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <script src="js/vendor/angular-1.5.8.min.js"><//script>
</head>
<body ng-app="app">
    <hello></hello>
    <hello></hello>
</body>

<script>
    var app = angular.module("app", []);
    app.directive("hello", function () {
        return {
            restrict: "E",
            template: '<div>Hi everyone!</div>',
            replace: true
    }
    });
<//script>
</html>

打开页面:

Hi everyone!
Hi everyone!






发表于: 1月前   最后更新时间: 21天前   游览量:146
上一条: angularjs输出data的内容
下一条: angularJs循环打印

评论…


  • 评论…
    • in this conversation