向模块添加依赖项后指令不起作用
Directives do not work after adding dependencies to module
我正在开发由节点服务器提供服务的 angular 应用程序,我正在尝试将依赖项包含在 core.js 文件中。在我将依赖项添加到模块之前,一切都运行良好。一旦我向模块添加依赖项,指令就会因某种原因停止工作。更具体地说,我要添加的依赖项是 btford.socket-io 并且与 bower 一起安装。
我已经尝试通过括号添加它,如下所示,并且 app.requires
也可以在下面的评论中看到。控制台中显示的错误是 [$injector:modulerr].
这是我的 core.js 文件:
var app = angular.module('test', ['btford.socket-io']);
// app.requires.push('btford.socket-io');
app.controller('testController', function ($scope, $http) {
$scope.test = "This is test.";
$scope.loadData = function() {
$http.get('/data').success(function(data) {
$scope.data = data;
});
};
$scope.loadData();
});
这里是layout.jade:
doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
script(src='http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js')
script(src='http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js')
script(src='/socket.io/socket.io.js')
script(src='javascripts/core.js')
body(ng-app="test")
block content
这里是index.jade:
extends layout
block content
div(ng-controller="testController")
p {{test}} Result should be 15 and is: {{5 + 10}}
br
p {{data[0].name}}
在添加依赖指令之前显示预期结果:
This is test. Result should be 15 and is: 15
MyName
但是添加依赖后,只显示为纯文本,报错[$injector:modulerr]:
{{test}} Result should be 15 and is: {{5 + 10}}
{{data[0].name}}
有谁知道为什么会这样,我怎样才能让它起作用?
如评论中所述,将 <script>
标记添加到 HTML 即可解决。
唯一要注意的是我必须将 app.use(express.static(path.join(__dirname, 'bower_components')));
添加到 app.js 才能使用想要的路由
我正在开发由节点服务器提供服务的 angular 应用程序,我正在尝试将依赖项包含在 core.js 文件中。在我将依赖项添加到模块之前,一切都运行良好。一旦我向模块添加依赖项,指令就会因某种原因停止工作。更具体地说,我要添加的依赖项是 btford.socket-io 并且与 bower 一起安装。
我已经尝试通过括号添加它,如下所示,并且 app.requires
也可以在下面的评论中看到。控制台中显示的错误是 [$injector:modulerr].
这是我的 core.js 文件:
var app = angular.module('test', ['btford.socket-io']);
// app.requires.push('btford.socket-io');
app.controller('testController', function ($scope, $http) {
$scope.test = "This is test.";
$scope.loadData = function() {
$http.get('/data').success(function(data) {
$scope.data = data;
});
};
$scope.loadData();
});
这里是layout.jade:
doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
script(src='http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js')
script(src='http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js')
script(src='/socket.io/socket.io.js')
script(src='javascripts/core.js')
body(ng-app="test")
block content
这里是index.jade:
extends layout
block content
div(ng-controller="testController")
p {{test}} Result should be 15 and is: {{5 + 10}}
br
p {{data[0].name}}
在添加依赖指令之前显示预期结果:
This is test. Result should be 15 and is: 15
MyName
但是添加依赖后,只显示为纯文本,报错[$injector:modulerr]:
{{test}} Result should be 15 and is: {{5 + 10}}
{{data[0].name}}
有谁知道为什么会这样,我怎样才能让它起作用?
如评论中所述,将 <script>
标记添加到 HTML 即可解决。
唯一要注意的是我必须将 app.use(express.static(path.join(__dirname, 'bower_components')));
添加到 app.js 才能使用想要的路由