如何使用ui-router的角度组件?

时间:2021-12-19 11:22:30

I am trying to use components (instead of controllers and templates) in ui-router. But this isn't working.
I'm following this article from their website.
Plunk

html:

我试图在ui-router中使用组件(而不是控制器和模板)。但这不起作用。我在他们的网站上关注这篇文章。 Plunk html:

  <body ng-app="myApp">
    <h1>Help!</h1>
    <a ui-sref="mypage">mypage</a>
    <ui-view></ui-view>
  </body>

js:

// 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>"
});

I'm neither getting the result, nor any errors. What I'm missing here?
Thanks in advance.

我既没有得到结果,也没有任何错误。我在这里缺少什么?提前致谢。

1 个解决方案

#1


1  

You don't have the right version.

你没有合适的版本。

Get the beta one:

获得测试版:

npm install --save angular-ui-router@1.0.0-beta.1

npm install --save angular-ui-router@1.0.0-beta.1

#1


1  

You don't have the right version.

你没有合适的版本。

Get the beta one:

获得测试版:

npm install --save angular-ui-router@1.0.0-beta.1

npm install --save angular-ui-router@1.0.0-beta.1