1

I was wondering whether someone could explain to me how AngularJs directives work.

I have the following code at the moment:

Index.html:

enter image description here

and my Login.html:

enter image description here

and finally my login.ts:

enter image description here

I'm trying to get that template file to be inserted into the index.html file. At the moment it currently just shows a blank screen, rather than the login.html, however when I remove the directive and copy and paste the code into the index.html it is fine and displays perfectly.

Any help is really appreciated.

7
  • check your console to see what error it is giving you, or paste this code somewhere so we can test it. It's a waste of effort to try and debug your code based on images. Commented Aug 29, 2016 at 15:30
  • Hi vileRaisin, there are no error messages in the console. Commented Aug 29, 2016 at 15:31
  • check your network tab, is it loading login.html? Commented Aug 29, 2016 at 15:31
  • Hi vileRaisin, no it is not. Commented Aug 29, 2016 at 15:32
  • I will create a fiddler maybe? Commented Aug 29, 2016 at 15:33

2 Answers 2

2

you named your directive loginDirective, but in your html you use it as <log-in/> which is the equivalent of logIn, not loginDirective

.directive('logIn', app.loginDirective);
Sign up to request clarification or add additional context in comments.

1 Comment

Yep. Thanks for that. Didn't know about the kebabcase.
0
###################################################################################
# The problem is in your Login.html ... Refer to solution 1 or 2 below
# Both with work. Just ensure that your directive name matches the 
# element 'E' you are injecting in your template.
###################################################################################


//---------------------------------------------------------------------------------
# Solution 1
# login.ts
.directive('loginDirective', app.LoginDirective);


# Login.html
<div>
    <login-directive></login-directive>
</div>


//---------------------------------------------------------------------------------
# Solution 2
# login.ts
.directive('logIn', app.LoginDirective);

# Login.html
<div>
    <log-in></log-in>
</div>

//---------------------------------------------------------------------------------

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.