Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:37:31+00:00 2026-06-13T08:37:31+00:00

Hi there I have this confirmable button directive which I am working on, The

  • 0

Hi there I have this “confirmable” button directive which I am working on,

The html code that will trigger the directive ‘confirmable’

      <span confirmable ng-click='users.splice($index,1)'></span>

the directive: (coffeescript)

  angular.module('buttons',[])

  .directive 'confirmable', () ->
    template: """
      <button class='btn btn-mini btn-danger'>
        Destroy
      </button>
    """
    replace: yes

So the end result I’d like to see generated with this directive is

      <button class='btn btn-mini btn-danger' ng-click='users.splice($index,1)'>
        Destroy
      </button>

So far I got it to work with a linking function inside the directive

  angular.module('buttons',[])

  .directive 'confirmable', () ->
    template: """
      <button class='btn btn-mini btn-danger'>
        Destroy
      </button>
    """
    replace: yes
    link: (scope, el, attrs) ->               <---------- linking function
      $(el).attr 'ng-click', attrs.ngClick

But I’ve gone through the directive documentation again, and found the scope property with the =, @, & operators but I am really unsure if they are what I need. Then there’s this transclude properties which I still need to understand but at the moment doesn’t seem to be helpful either. So while my linking function does the trick for now, but I thought I should ask to see if angular provides a more elegant solution.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:37:33+00:00Added an answer on June 13, 2026 at 8:37 am

    It sounds to me like you want to call a method from a parent scope from within your directive…

    I’ve put together a Plunk here

    (Sorry, I like JavaScript… so here goes)

    Here’s you’re parent controller.

    app.controller('ParentCtrl', function($scope) {
        $scope.fooCalled = 0;
        $scope.foo = function() {
            $scope.fooCalled++;
        };
    });
    

    Then your mark up

    <div ng-controller="ParentCtrl">
       Foo Called: {{fooCalled}}<br/>
       <button ng-click="foo()">Call From Parent</button><br/>
       <custom-control custom-click="foo()"></custom-control>
    </div>
    

    And your directive declaration:

    app.directive('customControl', function(){
       return {
         restrict: 'E',
         scope: {
            innerFoo: '&customClick'
         },
         template: '<button ng-click="innerFoo()">Call From Control</button>'
       };
    });
    

    The bit in the scope declaration in your directive definition is what ties the parent scope function reference to your directive’s scope so it can be called on click. That’s what the & is for there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code so far which perfectly but relies on there being a
hey there i have this code that should save a file from sql server
There have been a couple of threads on this topic in the past that
probably a simple one for you developers out there I have this code to
so there I have this code in rails <%= f.label :year, Year: %><br />
Hi there I have this code NSLog(@%@,URLRequestQueryString); NSString *sendToServerString = [NSString stringWithFormat:@http://mydomain.co.uk/req.php%@,URLRequestQueryString]; NSURL *sendToServer
There have been others that have asked this question but the common registry setting
I have a servlet which returns as response an html page that also includes
There have been many debates about this topic already here, but none of them
I have this situation: There are a login page with a login form (form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.