I am learning Angular JS and would like to create my custom directive. My javascript code is not showing any error but the custom directive is not getting replaced with my HTML template. Can you please guide on how to debug this issue or what is wrong with this code? jsFiddle link

<body ng-controller="customdirectivecontroller">
    <p>Placed custom directive here!</p>
    <mytextbox></mytextbox>
</body>

------------------
var customdirectiveapp = angular.module('customdirectiveapp', []);

customdirectiveapp.controller = ('customdirectivecontroller', function ($scope, $http) {
    $scope.name = "xxx";
});

customdirectiveapp.directive = ('mytextbox', function () {
    var directive = {};

    directive.restrict = 'E'; /* restrict this directive to elements */

    directive.template = "My first directive: ";

    return directive;
});
有帮助吗?

解决方案

There are several errors in your code

1) your variable name is wrong at directive defination it was customdirectveapp but it should be customdirectiveapp

2) your directive definations are wrong you should define controller,directive... like this

customdirectiveapp.controller('customdirectivecontroller', function ($scope, $http) {
    ....
});

instead of this

customdirectiveapp.controller = ('customdirectivecontroller', function ($scope, $http) {
    ....
});

and here is working PLUNKER of your application

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top