首页 > Web开发 > 详细

angularjs 指令间相互调用

时间:2017-05-28 11:31:06      阅读:370      评论:0      收藏:0      [点我收藏+]
<div ng-app="app">
    <div ng-controller="myctl">
       
        <button superman strength>按钮1111</button>
        <button superman strength speed>按钮22222</button>
    </div>
</div>
<script>
    var app = angular.module("app", []);
    app.controller("myctl", function ($scope) {
        $scope.info = "";
        $scope.showinfo = function () {
            $scope.info = "loading.....";
        };
    });

    app.directive("superman", function () {
        return {
            scope: {},
            controller: function ($scope) {
                $scope.arr = [];

                this.addL = function () { $scope.arr.push("length") };
                this.addS = function () { $scope.arr.push("speed") };
            },
            link: function (scope, element, attrs) {
                element.addClass("btn btn-success");
                element.on("click", function () {
                    alert(scope.arr);
                });
            }
        }
    });
    app.directive("strength", function () {
        return {
            require:^superman,
            link: function (scope, element, attrs, ctl) {
                ctl.addL();
            }
        }
    });
    app.directive("speed", function () {
        return {
            require: ^superman,
            link: function (scope, element, attrs, ctl) {
                ctl.addS();
            }
        }
    });

</script>

 

angularjs 指令间相互调用

原文:http://www.cnblogs.com/lunawzh/p/6915212.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!