JavaScript Adding directive makes controller undefined in angular js code

Here is my angular js app with html code

<html>
<head>
    <title></title>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/angular.min.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        angular.module("demo", []).controller('DemoController', function ($scope) {
            $scope.user = {
                dateOfBirth: new Date(1970, 0, 1)
            }
        });
    </script>
</head>
<body>
    <div ng-app="demo" ng-controller="DemoController">
        Date Of Birth:
        <my-datepicker type="text" ng-model="user.dateOfBirth" />
        <br />
        Current user's date of birth: <span id="dateOfBirthDisplay">{{user.dateOfBirth}}</span>
    </div>
</body>
</html>

It works fine.But the moment i add a directive to it, it shows error

Error: Argument 'DemoController' is not a function, got undefined

Here is the full code with directive

<html>
<head>
    <title></title>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="Scripts/angular.min.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        angular.module("demo", []).controller('DemoController', function ($scope) {
            $scope.user = {
                dateOfBirth: new Date(1970, 0, 1)
            }
        });
        angular.module("demo", []).directive('myDatepicker', function ($parse) {
            return {
                restrict: "E",
                replace: true,
                transclude: false,
                compile: function (element, attrs) {
                    var modelAccessor = $parse(attrs.ngModel);

                    var html = "<input type='text' id='" + attrs.id + "' >" +
            "</input>";

                    var newElem = $(html);
                    element.replaceWith(newElem);

                    return function (scope, element, attrs, controller) {

                        var processChange = function () {
                            var date = new Date(element.datepicker("getDate"));

                            scope.$apply(function (scope) {
                                // Change bound variable
                                modelAccessor.assign(scope, date);
                            });
                        };

                        element.datepicker({
                            inline: true,
                            onClose: processChange,
                            onSelect: processChange
                        });

                        scope.$watch(modelAccessor, function (val) {
                            var date = new Date(val);
                            element.datepicker("setDate", date);
                        });

                    };

                }
            };
        });
    </script>
</head>
<body>
    <div ng-app="demo" ng-controller="DemoController">
        Date Of Birth:
        <my-datepicker type="text" ng-model="user.dateOfBirth" />
        <br />
        Current user's date of birth: <span id="dateOfBirthDisplay">{{user.dateOfBirth}}</span>
    </div>
</body>
</html>

i'm following the tutorial from this link http://henriquat.re/directives/advanced-directives-combining-angular-with-existing-components-and-jquery/angularAndJquery.html

Answer:1

function handleCheckBoxEvent(cb){ var index = 0; switch (cb.id){ case "cb0": index = 0; alert(cb.id); break; ...

function handleCheckBoxEvent(cb){ var index = 0; switch (cb.id){ case "cb0": index = 0; alert(cb.id); break; ...

  1. switch checkbox
  2. switch checkbox value
  3. checkboxes switch android
  4. switch checkbox php
  5. ajax switch checkbox

I have this: txtNew.Attributes.Add("onkeyup", "alert('hi');"); But when I type in the textbox - no alert comes up. I just type and type and no alert ever comes up. Why is this not working? ...

I have this: txtNew.Attributes.Add("onkeyup", "alert('hi');"); But when I type in the textbox - no alert comes up. I just type and type and no alert ever comes up. Why is this not working? ...

I have a div that contains a settings icon that is a html miscellaneous symbol <span class="settings-icon">&#9881;</span> I have a jasmine test that checks the div contents to makes ...

I have a div that contains a settings icon that is a html miscellaneous symbol <span class="settings-icon">&#9881;</span> I have a jasmine test that checks the div contents to makes ...

I have just deployed my Express app to a production server and I'm no longer being served my static assets. My assets are in /public and I call the static middleware like so: // config.root => /...

I have just deployed my Express app to a production server and I'm no longer being served my static assets. My assets are in /public and I call the static middleware like so: // config.root => /...

  1. node js express
  2. node js express tutorial
  3. node js express example
  4. node.js express rest api example
  5. node.js express login example
  6. node.js express framework exploit
  7. node js express post
  8. node.js express mongodb crud
  9. node.js express upload image example
  10. node js express server
  11. node js express api
  12. node js express https
  13. node js express rest api
  14. node js express router
  15. node js express form post example
  16. node js express mysql
  17. node js express microservices
  18. node.js express framework
  19. node.js express mysql example
  20. node js express session