如何触发另一个指令模型

时间:2014-08-06 07:10:12

标签: angularjs angularjs-directive

我使用angular来编写一个对话框,当点击按钮时,追加元素。

html代码:

<div class="box" ng-app="myApp" ng-controller="conCtrl">
    <button ng-click="creatDir()">click me!</button>
</div>

dialogApp代码:

angular.module('dialogApp', []).
    factory('dialogFactory', ["$document","$interpolate",function ($document,$interpolate) {
        return {
            creatDialog:function (){
                //var div = angular.element("<div x-dialog-div></div>");
                var div = "<div x-dialog-div>{{name}}</div>";
                var interpolateDiv = $interpolate(div)({name:"wangyun"});
                $document.find("body").append(interpolateDiv);
            }
        };
    }]).
    directive('dialogDiv', [function () {
        return {
            restrict: 'A',
            template:"<div>1111111111111111</div>",
            link: function (scope, iElement, iAttrs) {
                console.log("123");
            }
        };
    }]);

myApp代码:

var myApp = angular.module("myApp",["dialogApp"]).
        controller('conCtrl', ['$scope',"$document","dialogFactory", function ($scope,$document,dialogFactory) {

            $scope.creatDir = function (){
                //$document.find("body").append(div);
                dialogFactory.creatDialog();
            };
        }]);

如何触发指令的 dialogApp ? 帮帮我,谢谢!

0 个答案:

没有答案