Angular JS-custome指令未替换为实际模板 [英] Angular JS - custome directive is not getting replaced with actual template

查看:91
本文介绍了Angular JS-custome指令未替换为实际模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Angular JS,并想创建我的自定义指令。
我的javascript代码未显示任何错误,但自定义指令未替换为我的HTML模板。
您能否指导如何调试此问题或此代码出了什么问题?
jsFiddle链接

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;
});


推荐答案

您的代码中有几个错误

1)您的变量名在指令定义时是错误的,它是 customdirectveapp ,但应为 customdirectiveapp

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

2)您的指令定义错误,您应该定义控制器,指令...像这样

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

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

代替此

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

,这里正在工作应用程序的LUN

这篇关于Angular JS-custome指令未替换为实际模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆