Javascript 如何在ui路由器中使用角度组件?
我试图在ui路由器中使用Javascript 如何在ui路由器中使用角度组件?,javascript,html,angularjs,Javascript,Html,Angularjs,我试图在ui路由器中使用组件(而不是控制器和模板)。但这不起作用。 我正在关注他们网站上的文章。 html: 救命啊! 我的页面 js: //寄存器 angular.module('myApp',['ui.router']); //配置 angular.module('myApp').config(函数($stateProvider){ $stateProvider.state({ 名称:“mypage”, url:“/mypage”, 组件:“新组件”//不能使用此组件。 }) });
组件
(而不是控制器
和模板
)。但这不起作用。我正在关注他们网站上的文章。
html:
救命啊!
我的页面
js:
//寄存器
angular.module('myApp',['ui.router']);
//配置
angular.module('myApp').config(函数($stateProvider){
$stateProvider.state({
名称:“mypage”,
url:“/mypage”,
组件:“新组件”//不能使用此组件。
})
});
//组成部分
angular.module('myApp')。组件('newComponent'{
模板:“这是来自组件”
});
我既没有得到结果,也没有任何错误。我错过了什么?提前感谢。您没有正确的版本 :
npm安装--保存用户界面-router@1.0.0-beta.1在plunker右侧切换版本,然后单击库
<body ng-app="myApp">
<h1>Help!</h1>
<a ui-sref="mypage">mypage</a>
<ui-view></ui-view>
</body>
// Register
angular.module('myApp', ['ui.router']);
// config
angular.module('myApp').config(function($stateProvider) {
$stateProvider.state({
name: 'mypage',
url: '/mypage',
component: "newComponent" // cant use this.
})
});
//component
angular.module('myApp').component('newComponent', {
template: "<h1> THis is from component <h1>"
});