答案 0 :(得分:1)
angular
.module('App', ['ui.router'])
.config(function($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise('/');
$stateProvider
.state('home', {
url: '/',
template: '<h1>Home</h1>',
controller: function(){
this.goDashboard = function() {
$state.go('status.service.dashboard');
};
this.goComponent = function() {
$state.go('status.service.component');
};
}
})
.state('status', {
template: '<h1>Status</h1><div ui-view></div>',
url: '/status',
resolve: {
service: function($http, $state){
return $http.get('/service.json')
.then (function (response) {
return response.data.id;
});
}
}
})
.state('status.service', {
url: '/service/:serviceId',
abstract: true,
resolve: {
setId: function(service,$stateParams){
$stateParams.serviceId = service;
}
},
params: {
serviceId: null
}
})
.state('status.service.dashboard', {
template: '<h1>Dashboard</h1>',
url: '/dashboard'
})
.state('status.service.component', {
template: '<h1>Component</h1>',
url: '/component',
controllerAs: '$ctrl'
});
})
var foo = require('a').foo // doesn't work with cyclic dependencies
import {foo} from 'a' // can work with cyclic dependencies*
var a = require('a')
function bar() {
a.foo() // can work with cyclic dependencies*
}
exports.bar = bar
在ES2015中,默认导入也可以是合格的导入(尽管有些人不同意),如果它们充当命名空间:
import * as a from 'a'
export function bar() {
a.foo() // can work with cyclic dependencies*
}
*具有循环依赖关系,您无法访问模块正文中的导入:
export default {
fn1,
fn2
}