在没有错误的情况下,没有显示任何内容。代码工作正常

时间:2017-04-08 21:00:43

标签: javascript html angularjs node.js ionic-framework

app.js

 var express= require('express');
var mongoose = require('mongoose');
var bodyParser=require('body-parser');
var cors= require('cors');
var app= express();
var multiparty= require('connect-multiparty');
var multipartMiddleware= multiparty();
var viewController=require('./controllers/viewController');
var shareController=require('./controllers/shareController');
var configs = require('./configs/config.js');
configs.setConfigs();

mongoose.connect(process.env.MONGO_URL);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended: true
}));
app.use(multipartMiddleware);
app.use(cors());

app.use('/app', express.static(__dirname+ '/app'));
app.get('/',function(req,res){
    res.sendFile(__dirname +'/index.html');
});
app.post('/share', multipartMiddleware, shareController.shareNewPicture);
app.get('/getNewPhoto', viewController.getNewPhoto);
/*app.use(function(req, res, next) {
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  res.header('Access-Control-Allow-Methods','POST, GET, OPTIONS, PUT');
next();
});*/
var port = 8080 || process.env.PORT;
app.listen(port, function(){
    console.log('Server Started '+ port);
});

server.js

 (function(window, angular, undefined)
{
    angular.module('app')
    .controller('viewCtrl',['$scope','$state','$http',function($scope,$state,$http)
    {   
        $scope.pics=[];
        $http.get('http://localhost:8080/getNewPhoto').then(function(response){
            $scope.pics=response.data;
            console.log('Hello photos are here');
        },function(err)
        {
            console.error("There's an error"+err);
        })
    }])
})(window,window.angular)

view.js

    <!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>
    <link rel="manifest" href="manifest.json">
    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <script src="lib/ionic/js/ionic.bundle.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.4.2/angular-ui-router.min.js"></script>
    <script src="cordova.js"></script>
    <script src="js/app.js"></script>
    <script src="js/components/view/view.js"></script>
  </head>
  <body ng-app="app">

    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title"></h1>
      </ion-header-bar>
      <ion-content>
        <div ui-view>
        </div>
      </ion-content>
    </ion-pane>
  </body>
</html>

我正在调用视图的index.html 的index.html

<div>
    <div ng-repeat='pics in pic'>
        <p> This is the view.html</p>
        <img ng-src={{pic.url}}/>
    </div>
</div>

这是我要展示的view.html view1.html

cols = paste("b", 1:6, sep = "")

y = integer(nrow(df))
for(j in seq_along(cols)) y[!df[[cols[j]]]] = j

y
#[1] 0 3 4 4 4 3 5 1 4 6

视野中没有任何事情发生。我试图获取照片的视图,但它没有显示任何错误或任何视图。请有人帮忙!!

1 个答案:

答案 0 :(得分:1)

在你写的ajax中:

$scope.pics=response.data;

但在你的重复你的写作:

<div ng-repeat='pics in pic'>

更改为

<div ng-repeat='pic in pics'>