AngularJS,ui-router& Firebase应用程序无法在Plunker中运行

时间:2014-11-22 00:22:57

标签: angularjs firebase angular-ui-router

我刚拿了一个我正在处理的应用程序并将其转换为Plunk但是Angular和/或ui-router没有填充index.html中的两个视图。在我的本地框上该应用程序加载正常,但我有应用程序模块化。因此,当我将其转换为Plunk时,我不得不重新连接文件,因为我无法在Plunker AFAIK中制作模块。此外,当我在一个单独的窗口加载Plunk并打开Dev Tools时,我没有错误,所以我现在不知所措。

以下是我制作的Plunk代码的链接:

http://plnkr.co/edit/2f1RITT6ysZhB5i0UcUw?p=preview

以下是嵌入视图的链接(如果您想使用Dev Tools,则更方便):

http://embed.plnkr.co/2f1RITT6ysZhB5i0UcUw/preview/posts

我应该提一下,路由必须以/posts结尾,因为它是名为posts的州的网址。我没有为根/网址定义状态。以下网址也失败了:

http://embed.plnkr.co/2f1RITT6ysZhB5i0UcUw/posts

提前致谢。

1 个答案:

答案 0 :(得分:3)

我做了一些改动。这是working plunker

首先,我升级了您的version to UI-Router 0.2.13 (修复了一些问题,只是总是使用最新版本)

/ post现在是默认

//$urlRouterProvider.otherwise('/');
$urlRouterProvider.otherwise('/posts');

我更改了你的控制器,不使用路由器参数,

// wrong old 
/*
app.controller('ProfileCtrl', function ($scope, $routeParams, Profile) {
        var uid = $routeParams.userId;
        $scope.profile = Profile.get(uid);
         Profile.getPosts(uid).then(function(posts) {
            $scope.posts = posts;
        });
    });
*/

// the way with UI-Router
app.controller('ProfileCtrl', function ($scope, $stateParams, Profile) {
    var uid = $stateParams.userId;
    $scope.profile = Profile.get(uid); 
    ...

只知道什么是帖子持有
此外,传递给userId进入状态包含如下值"simplelogin:82",以观察taht,我添加了已处理帖子的概述,其中显示的信息如下:

{
  "creator": "3lf",
  "creatorUID": "simplelogin:82", // this is passed as userId, is it ok?
  "title": "a",
  "url": "http://a",
  "$id": "-JazOHpnlqdNzxxJG-4r",
  "$priority": null
}

此外,这是一种固定的方式如何调用状态posts.postview

<!-- wrong -->
<!-- <a ui-sref="posts({postId:post.$id})">comments</a> -->
<!-- correct -->
<a ui-sref="posts.postview({postId:post.$id})">comments</a>

另外,如果将postview注入主要区域,这应该是它的定义

var postView = {
    name: 'posts.postview',
    parent: posts,
    url: '/:postId',
    views: {
        'navbar@': {
            templateUrl: 'nav.tpl.html',
            controller: 'NavCtrl'
        },
        //'@posts.postview': {
        '@': {
            templateUrl: 'postview.tpl.html',
            controller: 'PostViewCtrl'
        }
    }
};

全部检查here

摘要:工作导航属于帖子 - 用户...&#34;评论&#34;链接也在工作,但目标只是加载...还有许多其他错误......超出范围