我正在学习Angular JS,并希望创建我的自定义指令。 我的javascript代码没有显示任何错误,但自定义指令没有被我的HTML模板替换。 您能否指导如何调试此问题或此代码有什么问题? 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;
});
答案 0 :(得分:1)
您的代码中存在多个错误
1)您的变量名在指令定义时是错误的 customdirectveapp 但它应该是 customdirectiveapp
2)你的指令定义错误你应该定义控制器,指令......像这样
customdirectiveapp.controller('customdirectivecontroller', function ($scope, $http) {
....
});
而不是
customdirectiveapp.controller = ('customdirectivecontroller', function ($scope, $http) {
....
});
此处正在运行您的应用程序PLUNKER