模块在angularjs中不可用 index.html
app.module.js模块在angularjs中不可用 index.html,angularjs,Angularjs,app.module.js var intervieweeApp = angular.module('intervieweeApp', [ 'ngRoute', 'ngMessages', 'homeView' ]); angular.module('homeView', []); app.config.js angular. module('intervieweeApp'). config(['$routeProvider', function co
var intervieweeApp = angular.module('intervieweeApp', [
'ngRoute',
'ngMessages',
'homeView'
]);
angular.module('homeView', []);
app.config.js
angular.
module('intervieweeApp').
config(['$routeProvider',
function config($routeProvider) {
$routeProvider.
when('/home', {
template: '<home-view></home-view>'
}).
otherwise('/home');
}
]);
主视图/home-view.component.js
angular.
module('homeView').
component('homeView', {
templateUrl: 'home-view/home-view.template.html',
controller: ['$http',
function PhoneListController($http) {
console.log(15);
}
]
});
主视图/home-view.template.html
<p> at home </p>
在家里
错误
“homeView”模块不可用!您要么拼错了模块名,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。
加载index.html时,会出现此错误。我做错了什么?谢谢
由于使用script
标记导入js文件的顺序,您遇到了问题
创建模块时的最佳实践是使用。这有助于您不必考虑在index.html中导入js
文件的顺序
应用程序模块.ts
(function(){
angular.module('intervieweeApp', [
'ngRoute',
'homeView'
]);
})()
(function(){
angular.module('homeView', []);
})()
主视图.module.ts
(function(){
angular.module('intervieweeApp', [
'ngRoute',
'homeView'
]);
})()
(function(){
angular.module('homeView', []);
})()
大多数开源js插件中都使用相同的IIFE概念,因此这是一种标准做法
由于使用script
标记导入js文件的顺序,您遇到了问题
创建模块时的最佳实践是使用。这有助于您不必考虑在index.html中导入js
文件的顺序
应用程序模块.ts
(function(){
angular.module('intervieweeApp', [
'ngRoute',
'homeView'
]);
})()
(function(){
angular.module('homeView', []);
})()
主视图.module.ts
(function(){
angular.module('intervieweeApp', [
'ngRoute',
'homeView'
]);
})()
(function(){
angular.module('homeView', []);
})()
大多数开源js插件都使用相同的IIFE概念,因此这是一种标准做法您需要在导入其他内容之前导入模块注册。换句话说,
之前的
另外,作为旁注,angular.module(“名称”,[])
是一个模块注册(用于初始化模块的东西),其中依赖项在[]
位中指定。我注意到你在intervieweeApp
上做了两次;应该只保留其中的一个。作为警告,bootstrap.js
与AngularJS不能很好地配合。@Protozoid谢谢。这解决了问题。但当我转到“主页”时,页面不会更改,console.log函数也不会更改executed@Thunfische:您看过我的解决方案了吗?您需要在导入其他内容之前导入模块注册。换句话说,
之前的
另外,作为旁注,angular.module(“名称”,[])
是一个模块注册(用于初始化模块的东西),其中依赖项在[]
位中指定。我注意到你在intervieweeApp
上做了两次;应该只保留其中的一个。作为警告,bootstrap.js
与AngularJS不能很好地配合。@Protozoid谢谢。这解决了问题。但当我转到“主页”时,页面不会更改,console.log函数也不会更改executed@Thunfische:你看了我的解决方案了吗?哦,我没有把ng视图添加到索引html中。谢谢哦,我错过了将ng视图添加到索引html中。谢谢