2

我编写了一个基本的 angularJS + mongoLab 应用程序。获取数据的代码工作正常,在 Chrome 开发者工具中我可以看到响应为:

[ { "_id" : { "$oid" : "5166c406e4b08774fa6844a9"} , "tag" : "Software Developer"} , { "_id" : { "$oid" : "51679cbde4b05c7db8d21e70"} , "tag" : "Project Management"} ]

在我看来,我有:

<ul>
                <li ng-repeat="tagz in tags">
                    {{tagz.tag}}
                </li>
            </ul>

但是当我在浏览器上显示时,我看到的只是

  • 点,但不显示标签值。我的控制器有:

    'use strict';
    // Define our root-level controller for the application.
            Riadd.controller(
                "AppController",
                function( $scope, $route, $routeParams, Tags){
    
    
    
    
                    // Update the rendering of the page.
                    var render = function(){
                        $scope.tags = Tags;
    
                        // Pull the "action" value out of the
                        // currently selected route.
                        var renderAction = $route.current.action;
    
                        // Also, let's update the render path so that
                        // we can start conditionally rendering parts
                        // of the page.
                        var renderPath = renderAction.split( "." );
    
                        // Grab the username out of the params.
                        //
                        // NOTE: This will be undefined for every route
                        // except for the "contact" route; for the sake
                        // of simplicity, I am not exerting any finer
                        // logic around it.
                        var username = ($routeParams.username || "");
    
                        // Reset the booleans used to set the class
                        // for the navigation.
                        var isHome = (renderPath[ 0 ] == "home");
                        var isFriends = (renderPath[ 0 ] == "friends");
                        var isContact = (renderPath[ 0 ] == "contact");
    
                        // Store the values in the model.
                        $scope.renderAction = renderAction;
                        $scope.renderPath = renderPath;
                        $scope.username = username;
                        $scope.isHome = isHome;
                        $scope.isFriends = isFriends;
                        $scope.isContact = isContact;
    
                    };
    
                    // Listen for changes to the Route. When the route
                    // changes, let's set the renderAction model value so
                    // that it can render in the Strong element.
                    $scope.$on(
                        "$routeChangeSuccess",
                        function( $currentRoute, $previousRoute ){
    
                            // Update the rendering.
                            render();
    
                        }
                    );
    
                }
            );
    

    知道我哪里出错了吗?

  • 4

    1 回答 1

    0

    请参考https://github.com/pkozlowski-opensource/angularjs-mongolab-promise/blob/master/README.md

    恕我直言,而不是

    $scope.tags = Tags;
    

    你会需要

    Tags.all(function(tags){
      $scope.tags = tags;
    });
    
    于 2013-04-19T15:29:25.917 回答