1. 程式人生 > >angularjs 指令間相互調用

angularjs 指令間相互調用

module directive pan bsp ... 調用 add color win

<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 指令間相互調用