Angularjs - Pass argument to directive

后端 未结 6 1126
日久生厌
日久生厌 2020-12-04 19:08

Im wondering if there is a way to pass an argument to a directive?

What I want to do is append a directive from the controller like this:

$scope.titl         


        
6条回答
  •  感动是毒
    2020-12-04 19:18

    Insert the var msg in the click event with scope.$apply to make the changes to the confirm, based on your controller changes to the variables shown in ng-confirm-click therein.

    
    
    
    
    
    app.directive('ngConfirmClick', [
      function() {
        return {
          link: function(scope, element, attr) {
            var clickAction = attr.confirmedClick;
            element.on('click', function(event) {
              var msg = attr.ngConfirmClick || "Are you sure? Click OK to confirm.";
              if (window.confirm(msg)) {
                scope.$apply(clickAction)
              }
            });
          }
        };
      }
    ])
    

提交回复
热议问题