1

I have created two directives and included them in my html. However, only the first one executes and nothing after it.

<div ng-app="myApp">
    <div ng-controller="MyCtrl">
        <div directive-one=""/> 
        <div directive-two=""/>
        <div> Hello I am {{name}} and I am {{age}} years old!</div>
    </div>

    <script type="text/ng-template" id="myTemplate.html">
        <div>Name: <input type='text' ng-model='name'/></div>
    </script>
</div>

Javascript:

var app = angular.module('myApp', []);

app.controller('MyCtrl', function ($scope) {
    $scope.name = "Jason";
    $scope.age = "20";
});

app.directive('directiveOne', function () {
    return {
        replace: true,
        template: "<div>Age: <input type = 'text' id = 'age' ng-model='age'>
                  </input></div>"
    }
});

app.directive('directiveTwo', function () {
    return {
        replace: true,
        templateUrl: "myTemplate.html"
    }

});

Here is the fiddle: DEMO

Can't figure out what the issue is. Any help is appreciated.

1 Answer 1

2

You have to close your div tags with the directives in them and you don't need the ="" after either.

<div directive-one></div> 
<div directive-two></div>

Here's an updated fiddle with it working.

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

2 Comments

That was dumb. Thanks
I'm surprised why this is not consider as close of element . it has "/" at the end - <div directive-one=""/> <div directive-two=""/>

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.