javascript - 如何在 ui-router 中使用 Angular 组件?

标签 javascript html angularjs

我正在尝试在 ui-router 中使用 components(而不是 controllerstemplates)。但这不起作用。
我正在关注 this他们网站上的文章。
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>"
});

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

最佳答案

您没有正确的版本。

Get the beta one :

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

关于javascript - 如何在 ui-router 中使用 Angular 组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39809377/

相关文章:

javascript - 将数组拆分为给定大小的 block

javascript - 元素至少有一个选择器

javascript - 为什么我的 javascript 地理编码函数返回空白结果?

PHP 脚本未执行 - 登录表单捕获

javascript - 滚动时动画固定导航 - 错误

javascript - AngularJS : How to read data of JSON file on button click?

javascript - CSS3 - 使用过渡的可变高度 Accordion

javascript - onScroll 通过在屏幕上可见将类添加到 div

angularjs - 如何在 angularjs 中发送具有多个参数的 POST?

angularjs - 如何将 DOM 函数发送到 AngularJS 中的指令?