0

I am using this tutorial to understand how to display an image using directives with an isolate scope. What am i missing to get the attribute to bind? In my ide, I can output the image but the directive is not working. The fiddle displays nothing :-(

Fiddle:http://jsfiddle.net/gogirl/Stm3j/

This is outputted in my program:

 output:{{photo.url}}
<img ng-src='http://www.w3schools.com/js/pic_bulboff.gif' />

This is not outputted:

 <my-d photo-src={{photo.url}} ></my-d>
1
  • Chen-Tsu: the reason I believe that no controller is needed is that there is no change in state. The init directive is enough to pass on the data. Commented Feb 11, 2014 at 19:32

2 Answers 2

2

You have residual data in your jsfiddle configuration

Here is what I did to make it work

  1. Remove the external resources because you use angular 1.0.1 with angular 1.2.1
  2. Remove in options panel the body tag myModule
  3. Remove the call of the undefined variable app and query it with angular.module

jsfiddle updated here

// My Main Application File
angular.module('myApp', ['myDirectives']);

// My Directives File
angular.module('myDirectives', []);

// Controller One File
angular.module('myDirectives', []).directive('myD', function () {
    return {
        restrict: 'E',
        template: '<figure> <img ng-src="{{photoSrc}}"/> </figure>',
        replace: true,
        // pass these two names from attrs into the template scope
        scope: {
            photoSrc: '@'
        }
    }
})
Sign up to request clarification or add additional context in comments.

2 Comments

Merci Aduch. As you can see our answers crossed but am so happy that I can use chaining again.
Yes it is sometimes hard to work on several versions of a configuration, step back the go forth again leaving some traces ;)
0

Working Examle

All is working fine now when i switched the original module chaining method with the global app method:

   var app = angular.module("myApp", []);
       app.directive('myD', function() {
           return {
               restrict: 'E',
               template: '<figure> <img ng-src="{{photoSrc}}"/> </figure>',
               replace: true,
               // pass this name from attrs into the template scope
               scope: {
                   photoSrc: '@'
               }
       }
    });

But I wont be a happy camper until I figure out what is wrong with the chaining declaration as it works fine elsewhere. Any takers? Fiddle still not working so i think it may be an issue with it being a fiddle. EDIT: WORKS fine also with chaining method..One baby step at a time :-)

Comments

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.