ocombe / ocModal

An angularJS modal directive & service
66 stars 16 forks source link

scope clear #16

Closed sudheerDev closed 6 years ago

sudheerDev commented 8 years ago
    ocModal.directive('ocModalOpen', ['$ocModal', function($ocModal) {
        return {
            restrict: 'A',
            require: '?modal',
            link: function($scope, $element, $attrs) {
                $element.on('click touchstart', function(e) {
                    e.preventDefault();
                    e.stopPropagation();
                    var newScope = $scope.$new();
                    var params = newScope.$eval($attrs.ocModalOpen);
                    if(params) {
                        if(typeof params === "number") {
                            params = { url: $attrs.ocModalOpen };
                        } else if(typeof params === "string") {
                            params = { url: params };
                        }
                        if(!params.url) {
                            throw "You need to set the modal url";
                        }
                        $scope.$apply(function() {
                            $ocModal.open(params);
                        });
                    }
                });
            }
        };
    }]);

Should the newScope here destroyed on $scope $destroy?

And would it be better to set reference of modals to null instead of deleting them?

remove: function(id) {
  modals[id || '_default'] = null;
  // delete modals[id || '_default'];
},