Angular 1.5和新的组件路由器

时间:2015-11-11 14:29:07

标签: angularjs angular-new-router

我使用了角度1.5 beta 2和来自Angular 2 alpha 45的新路由器 我无法找到使用Angular 1的最新路由器的使用示例 我可以使用lua_getglobal(L, "lgd"); lua_getfield(L, -1, "value_pos_x"); cr->value_pos_x = lua_tointeger(L, -1); lua_getfield(L, -2, "value_pos_y"); cr->value_pos_y = lua_tointeger(L, -1); lua_getfield(L, -3, "time"); cr->time = lua_tointeger(L, -1); if (lua_tointeger(L, -1) != lua_isinteger(L, -1)) printf("The entry %s is invalid;", capture_lua_getfield_name); 找到Angular 2的路由器用法示例。

有人可以解释我如何配置角度1控制器吗?并且,如果可能的话,一个完整的工作示例?

2 个答案:

答案 0 :(得分:14)

Update They have stopped working on this version of the Router and started a version 3 with different APIs. As of June 20, 2016 there was no recommended way for using the router v3 with Angular 1. I'm not sure if this has changed since. This question and answer below relates to Router v2 (aka ComponentRouter).


Obsolete API
A few sites indicate that a component in Angular 1 (for the purpose of the new router) is a controller registered as [name]Controller and a template picked up from component/[name]/[name].html. This is now obsolete.

New API
This discussion contains recent information, explaining how to get the latest Angular 1 new router version.

The component used in the configuration is mapped to a directive registered with the component name. See this sample.

angular.module('app.home', [])
.directive('home', function() {
  return {
    template: 'Hello {{ home.text }}',
    controller: function HomeController() {
      this.text = 'World';
    },
    controllerAs: 'home'
  }
});

With Angular 1.5 there is a new syntax for registering components, see here. I've used it with this syntax:

angular.module('app.home', [])
.component('home', {
  restrict: "EA",
  template: 'Hello {{ home.text }}',
  controller: function HomeController() {
    this.text = 'World';
  }
  // to configure a child route
  //,$routeConfig: [
  //  { aux: "/son", component: "son", as: "Left" },
  //  { aux: "/daughter", component: "daughter", as: "Left" }]
});

答案 1 :(得分:4)

虽然此时它还很新,但您也可以使用带有新角度路由器的根组件。该组件可以将其他组件作为子组件。

我跟随Pete Bacon Darwin的例子来推出一个版本。 https://github.com/petebacondarwin/ng1-component-router-demo

在他的版本中注意主要组件在运行块中传递$ router.config并识别3个点的子项。

.run(function($router) {
    $router.config([
    { path: '/...', name: 'App', component: 'app', useAsDefault: true }
    ]);

我正在使用angular 1.5.0跟随他的github。我遇到了一些问题,发布了一些发布候选版本。