AngularDart路线

时间:2014-07-31 02:55:15

标签: dart angular-dart

有谁能告诉我我的同志有什么不对:

import 'package:angular/angular.dart';
import 'package:angular/application_factory.dart';
import 'package:angular/routing/module.dart';

class myApp extends Module {
    myApp() {
        bind(RouteInitializerFn, toValue: initRoutes);
    }
}

void initRoutes(Router router, RouteViewFactory views) {
views.configure({
  'new': ngRoute(path: '/new', view: 'new.html'),
  'demohome': ngRoute(path: '/list', view: 'list.html')
 });
}

main() {

 var module = new Module()
  ..bind(myApp);

 applicationFactory().addModule(module).run();
}

html文件非常简单,我只想测试路由,因为我注意到在这方面发生了很多变化:            家       新条目          

感谢

1 个答案:

答案 0 :(得分:0)

感谢所有人都试图提供帮助,我现在完全得到了以下代码:

  // the main.dart file;
      import 'package:angular/angular.dart';
      import 'package:angular/application_factory.dart';
      import 'package:angular/routing/module.dart';

      class myApp extends Module {
          myApp() {
            bind(RouteInitializerFn, toValue: initRoutes);
            bind(User);
          }
      }

      void initRoutes(Router router, RouteViewFactory views) {
      views.configure({
        'new': ngRoute(path: '/new', view: 'new.html'),
        'demohome': ngRoute(path: '/list', view: 'list.html')
       });
      }

      main() {         
        applicationFactory().addModule(new myApp()).run();
      }

      @Controller(
          selector: '[user-input]',
          publishAs: 'userCtrl') 

      class User {
        String userName = 'defaultName';
      }

和html文件是:

  <!doctype html>
  <html ng-app>

    <head>
      <meta charset="utf-8">
      <title>AngulrRoute Test</title>
      <link rel="stylesheet" href="todo.css">
    </head>

    <body>
        <h1>AngulrRoute Test</h1>

        <div user-input>Hello user {{userCtrl.userName}}!</div>

      <nav>
        <a href="/list">List</a>
        <a href="/new">New Entry</a>
      </nav>
      <ng-view></ng-view>


  <script type="application/dart" src="todo.dart"></script>
  <script type="text/javascript" src="packages/browser/dart.js"></script>


    </body>
  </html>