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 9216389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:24:26+00:00 2026-06-18T02:24:26+00:00

i like to make a custom component using directive. i checked lot of tutorials

  • 0

i like to make a custom component using directive. i checked lot of tutorials and its get confusing me can anyone explain how a directive works. the component i am planing to make is

<shout-list></shout-list>

the template for shout list will be like this

<div class="shout" ng-repeat="shout in shouts">
    <p>{{shout.message}}</p>
    <img src="media/images/delete.png" width="32" height="32" ng-click="deleteShout({{$index}},'{{shout._id}}')"/>
</div> 
  • 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-18T02:24:28+00:00Added an answer on June 18, 2026 at 2:24 am

    Here’s your directive, with some inline comments:

    angular.module( 'directives', [] ).directive( 'shoutList', function () {
      return {
        restrict: 'E', // allow as an element; the default is only an attribute
        scope: {       // create an isolate scope
          shouts: '='  // map the var in the shouts attribute to this scope
        },
        templateUrl: 'templates/shoutList.html', // load the template file
        controller: function ( $scope ) {
          // we declare a your function for use in the view
          $scope.deleteShout = function ( idx, id ) {
            // do whatever
          };
        }
      };
    });
    

    And the template file:

    <div class="shout" ng-repeat="shout in shouts">
      <p>{{shout.message}}</p>
      <img src="media/images/delete.png" width="32" height="32" 
        ng-click="deleteShout({{$index}},'{{shout._id}}')" />
    </div> 
    

    And now you can use it in your code, like so:

    Controller:

    .controller( 'MainCtrl', function ( $scope ) {
      $scope.myShouts = // ...
    });
    

    View:

    <shout-list shouts="myShouts"></shout-list>
    

    Hope this helps!

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

Sidebar

Related Questions

I would like to make the custom UISlider, something like this |o----------| -> |-----O------|
I'd like to make a custom button in wxPython. Where should I start, how
How to make a custom Edittext,so that it will look like as 45 degree
I would like make a script using PHP (probably need JS) to send POST
A quick background : I have put a captcha using the primefaces custom component
I want to add aboutbox/dialogbox on my Custom component. how to make the small
The spark panel component for example can be written like this <Panel title=Skinny> <child
I made a composite component and declared a custom namespace in my taglib like
I am trying to make a slideshow-like application in Java using NetBeans. I have
Quite frequently, I'm using custom Wicket components to render model objects. Objects can sometimes

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.