Angular应用程序don't显示$scope值,而不是错误消息

Angular app don't show $scope values, not error message

本文关键字:消息 错误 scope don 应用程序 显示 Angular      更新时间:2023-09-26

我正在学习MEAN堆栈,并试图在本课程的demo基础上构建一个应用程序(thinkster.io/MEAN堆栈教程#使用mongoose创建模式)。我检查了一下有卷曲的db,没关系,但有棱角的不要把它们绑在一起。

-->这是视图(index.ejs):

<html>
<head>
    <meta charset="UTF-8">
    <title>demo</title>
    <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.10/angular-ui-router.js"></script>
    <script src="javascripts/angularApp.js"></script>
</head>
<body ng-app="demo">
<div class="row">
  <div class="col-md-6 col-md-offset-3">
    <ui-view></ui-view>
  </div>
</div>
<script type="text/ng-template" id="/home.html">
    <div class="page-header">
    <h1>Patients : </h1>
  </div>
    <div ng-repeat="patient in patients">
        <a>{{patient.name}} - Nom: {{patient.surname}} - Age: {{patient.old}}</a>
    </div>
</script>
</body>
</html>

-->这是我的节点js代码(index.js)

var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var Patient = mongoose.model('Patient');
/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});
/* GET all patients */
router.get('/patients', function(req, res, next){
    Patient.find(function(err, patients){
        if(err){ return next(err); }
        res.json(patients);
    });
});
//configure express : retrieve automatically post by id
router.param('patient', function(req, res, next, id){
    var query = Patient.findById(id);
    query.exec(function(err, patient){
        if(err){ return next(err); }
        if(!patient){ return next(new Error("Aucun patient dans la base...")); }
        req.patient = patient;
        return next();
    });
});
module.exports = router;

-->这是我的角度代码(angularApp.js)

var app = angular.module('flapperNews', ['ui.router']);
app.config([
    '$stateProvider',
    '$urlRouterProvider',
    function($stateProvider, $urlRouterProvider){
        $stateProvider
            .state('home', {
                url: '/home',
                templateUrl: '/home.html',
                controller: 'MainCtrl',
                resolve: {
                    postPromise: ['posts', function(posts){
                        return posts.getAll();
                    }]
                }
            });
        $urlRouterProvider.otherwise('home');
    }]);
app.factory('posts', ['$http', function($http){
    var o = {
        posts: []
    };
    o.getAll = function() {
        return $http.get('/posts').success(function(data){
            angular.copy(data, o.posts);
        });
    };
    return o;
}]);
app.controller('MainCtrl', [
'$scope',
'posts',
function($scope, posts){
    $scope.posts = posts.posts;
}]);

您没有在html 中绑定控制器"MainCtrl"