【发布时间】:2023-04-11 07:47:02
【问题描述】:
学习和练习 npm build,我尝试使用 npm run build 编译我的脚本,我得到了一个错误
[$injector:nomod] 模块“testApp”不可用!您要么拼错了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。
任何建议。谢谢
app.js
import angular from 'angular';
import 'angular-ui-router';
import './services/router.js';
angular.module('testApp', [
'ui-router'
]);
-----------------------------
my roter.js
'use strict';
angular
.module('testApp')
.config([
'$urlRouterProvider',
'$stateProvider',
'$locationProvider',
function($urlRouterProvider, $stateProvider, $locationProvider) {
$locationProvider.html5Mode(false).hashPrefix('');
$urlRouterProvider.otherwise('/');
$stateProvider
.state('home', {
url: '/',
templateUrl: 'components/views/homepage.html',
controller: 'productController'
})
.state('about', {
url: '/about',
templateUrl: 'components/views/about.html'
})
.state('product', {
url: '/product/:id/:name',
templateUrl: 'components/views/product.html',
controller: 'productViewController'
})
}]);
【问题讨论】:
-
注入的ui路由器应该是
ui.router这里是一个例子Using ES6 modules with angular