角模块不起作用?

菠菜

我有以下代码上下文。但是由于某种原因myApp,当我最初定义它并尝试在多个情况下将其与mod变量一起使用时它会返回未定义的错误

我究竟做错了什么?

https://jsfiddle.net/wL54j8g9/3/

angular.module('myApp', []);

var mod = angular.module('myApp');

mod.directive('myList', myDirective);
mod.directive('myObject', myObject);

function myDirective(){
    var opt = {
    restrict: 'E',
    template: '<ul><li>This is One</li><li>This is Two</li></ul>'
  };
  return opt;
}

function myObject(){
    var opt = {
    restrict: 'A',
    template: '<p>A Bouncing Before Park Me Bird Joe You\'re She Tell Toenails Mix Gox I Matter TV Battered You\'ll Vim Didn\'t Oh Snapped Silly</p>'
  };
  return opt;
}
丹尼尔·贝克(Daniel Beck)

两个问题:

angular.module('myApp', []);
var mod = angular.module('myApp');

应该只是

var mod = angular.module('myApp', []);

(嗯。实际上,经过一些试验,我发现只要您正确注入Angular,它仍然可以按照您的方式工作……尽管有点多余,但我仍然建议将它们组合起来。)

更重要的是,在您的小提琴中,您正在注入Angular的“ onLoad”-如果将其更改为“ nowrap in <head>”,它将起作用;参见https://jsfiddle.net/rtrb8ngp/ng-app实例化Angular模块时,带有的DOM元素必须已经存在(否则,您需要使用引导程序方法来初始化它)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章