3

I made a custom directive:

js part:

angular.module("myDirectives", []).directive("ngShowbox", function(){
  return {
    restrict: "E",
    scope: {
      title: "="
    },
    template: "<a href='#' ng-click='show($event)'>{{title}}</a>",
    controller: function($scope, $element){
      $scope.show = function(event){
        // do something...
      }      
    }
  }
});

html part:

<ng-showbox title="whatToPutHere??"></ng-showbox>

I would like to pass some text from the title attribute, then my template will show the text. How can I make it?

Thank you very much :)

1 Answer 1

6

Use @ in directive scope:-

scope: {
      title: "@"
    },

Plunker for you :)

Sign up to request clarification or add additional context in comments.

2 Comments

just a note, if you assign the value of title to a controller scope value, then you need to use title: "=". :), if you need just the string value, not as a scope value inside the title you can use title: "@"
Yup exactly :) "=" will give you two way binding power where as "@" just bind the string to the scope.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.