Hi,
just add "scope: true" to your directive def object.
Try this one to understand :
(function() {
angular.module('app', []).directive('myMonkey', function() {
var obj;
return obj = {
restrict: 'E',
scope: true,
replace: true,
template: '<div>{{src}}<img ng-src="{{src}}" width="150"></div>',
link: function($scope, elem, attrs) {
if (attrs.sad === void 0) {
return $scope.src =
'http://martouf.ch/utile/images/divers/2010_10_08_21_25_monkey-face-cartoon.png';
} else {
return $scope.src =
'http://www.clker.com/cliparts/G/K/m/d/a/3/sad-monkey-face-2-md.png';
}
}
};
})
}());
and read this (scope part) :
http://amitgharat.wordpress.com/2013/06/08/the-hitchhikers-guide-to-the-directive/
Marc.
On 14/02/2014 12:01, Bernhard Rode wrote:
> I have a simple directive myMonkey, which sets a image based on the
>
> which is used twice in a page.
>
> <my-monkey></my-monkey>
> <my-monkey sad></my-monkey>
>
> Angular shows two sad monkeys...but it should show a happy and a unhappy
> one.
>
> if we comment out the "<my-monkey sad></my-monkey>", a lucky monkey is
> being shown.
>
> if we change the order to
>
> <my-monkey sad></my-monkey>
> <my-monkey></my-monkey>
>
> then two lucky monkeys are being shown.
>
> What am I doing wrong?
>
> See my plunker for the example:
>
> http://plnkr.co/edit/fYBOJNnpV1EJv6AxSWXo?p=preview
>
> BTW. Yes, we really have a monkey directive in our production code ;)
>
> Greetz B.
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.