javascript - Angular 指令无法使用 Yeoman 工作

标签 javascript angularjs angularjs-directive gruntjs yeoman

我正在尝试测试使用以下命令创建的指令

yo angular:directive countriesDirectives

这是经过一些更改后的指令

'use strict';

/**
 * @ngdoc directive
 * @name miaplicacionApp.directive:countriesDirective
 * @description
 * # countriesDirective
 */
angular.module('miaplicacionApp')
  .directive('countriesDirective', function () {
    return {
      restrict: 'E',
      template: '<h1>hjbjhbjhbjbjhbjhbjhbjhbjhbjhbjhbjhb</h1>',
      link: function postLink(scope, element, attr) {
        element.text('this is the countriesDirective directive');
      }
    };
  });

这里我将该指令包含在我的index.html中

<div class="container cont">
        <h1>jkm</h1>
         <countriesDirective></countriesDirective>
         <br>
         <br>
         <br>
         <br>
        <ng-view></ng-view>
    </div>

然后我运行“gruntserve”。一切都按我的预期工作,但指令不起作用。值得一提的是,当 Yeoman 创建应用程序时,它包含其工作所需的所有必要文件。但由于某种原因我的指令不起作用。

最佳答案

HTML 标记应为 <countries-directive></countries-directive> .

Angular 将camelCase 转换为spine-case。

Angular normalizes an element's tag and attribute name to determine which elements match which directives. We typically refer to directives by their case-sensitive camelCase normalized name (e.g. ngModel). However, since HTML is case-insensitive, we refer to directives in the DOM by lower-case forms, typically using dash-delimited attributes on DOM elements (e.g. ng-model).

关于javascript - Angular 指令无法使用 Yeoman 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33377965/

相关文章:

angularjs - 如何使用 Google Analytics 跟踪用户 ID 并且登录后不重新加载页面?

javascript - 将值传递给angular js中的自定义指令

javascript - 无法更新我的 MySQL 数据库中的一个单元格?

javascript - 使用 moment.js 转换日期/时间格式

javascript - 对于 HTML/javascript i18n,MySQL + PHP 的替代方案是什么?

javascript - Angular.js ng-view忽略路由

data-binding - AngularJs 绑定(bind)指令到 getter 属性

angularjs - 嵌套指令未编译

javascript - 查找 Angular 指令中的所有元素

javascript - Google Apps 脚本 - 上传文件并将数据发布到电子表格