I'm new to AngularJS. Need some help with the directive I created. This is My HTML:

我新AngularJS。我创建的指令需要一些帮助。这是我的HTML:

<data-table template-url="dataTable.html" info="someData"></data-table>

I get "someData" from server in my controller - directive.js:

我在我的控制器directive.com中从服务器获取“someData”。

app.directive('dataTable', function() {
 return{
    restrict: 'E',
    scope: {
        data : '=info'
    },
    link: function($scope,elem,attrs){
         ///some code here.
    },
    templateUrl : function(elem, attrs) {
        return attrs.templateUrl;
    }
});

The issue is when I debug my code, it come to the directive by doesn't go inside. (I used javascript debug in chrome). Is there anything I'm missing. The restrict Tag is proper, name is correct what else is needed? I did look at the similar questions but couldn't find any solution. Here is a fiddle : Demo

问题是,当我调试我的代码时,它的指令是不进入内部的。(我在chrome中使用了javascript调试)。有什么我遗漏的吗?限制标签是正确的,名称是正确的,还需要什么?我确实研究过类似的问题,但没有找到任何解决办法。这是一个小提琴:演示

1 个解决方案

#1


2

You can't use directive names starting with data-* because its reserved by AngularJS ng core namespaces. Just use an other name to start with and you will be fine.

不能使用以data-*开头的指令名,因为它由AngularJS ng核心名称空间保留。只要用另一个名字开头就可以了。

<my-data-table template-url="dataTable.html" info="someData"></my-data-table>

And your directive:

和你的指令:

myApp.directive('myDataTable', function() {
  return {
    scope: {
      data: '=info'
    },
    link: function($scope, elem, attrs) {
      ///some code here.
      console.log(attrs.templateUrl);
    },
    templateUrl: function(elem, attrs) {
       return attrs.templateUrl;
    }
  }
});

更多相关文章

  1. $ postLink的角度组件/指令运行得太早
  2. element.replaceWith在自定义指令的链接中仅在第一次调用时工作
  3. Mac下MySQL-python安装及EnvironmentError: mysql_config not fo
  4. Python 2.6.2中的ElementTree处理指令支持?
  5. python在文本开头插入一行
  6. 通过指令“ps -l”查看进程信息
  7. 常见压缩格式的区别,及 Linux 下的压缩相关指令
  8. Linux学习笔记_1.Linux常见指令
  9. Linux下文件的打包、解压缩指令——tar,gzip,bzip2

随机推荐

  1. js关于Function.prototype.bind
  2. RichFaces 3.3.3 和 JSF 2.0
  3. js中ajax获取json数据遍历提示undefined
  4. 在单选按钮上选中/取消选中,加载/隐藏部分
  5. javascript 的MD5代码备份,跟java互通
  6. 使用AngularJS隐藏滚动div
  7. 简单实现一个文件上传的进度条
  8. 如何在当前视图中始终保持水平底部滚动条
  9. JavaScript(ES5)使用保留字作函数名
  10. JQuery纯前端导入Excel文件,兼容IE10及IE9