无法使用JSON中的AngularJS路径显示图像

时间:2015-12-17 10:21:50

标签: javascript angularjs json

我想清楚地解释一下我的问题。 无法使用来自Json的angularJS路径和存储在本地文件夹中的Image

来显示图像

HTML

<div controller="canController">
<tr ng-repeat="can in canList">
    <td>{{can.can_name}}</td>
    <td><img ng-src="{{can.can_path}}" alt="{{can.can_name}}"></td>
</tr>
</div>

canController.js

$http.get('/auth/canUploadList').success(function(response){
            $scope.canList = response;
            console.log($scope.canList);
        }); 

JSON:

[
{
_id: "5672747ab0c1a0841314bf76",
can_path: "uploads/1450341498134-Bisleri.jpg",
can_name: "Hapserve",
__v: 0,
date: "2015-12-17T08:38:18.149Z"
},
{
_id: "56728c05a14c24701299fb52",
can_path: "uploads/1450347525373-Kinley.png",
can_name: "Kinley",
__v: 0,
date: "2015-12-17T10:18:45.397Z"
}
]

获得如下输出: output_image

帮我解决这个问题

更新

router.get('/canUploadList', function(req, res){
        Can.find(function(err, docs){
            res.json(docs);
        });
    });



router.post('/canUpload', upload.single('can_image'), function(req, res, next) {
        console.log(req.body);
        console.log(req.file);
        var newCan = Can();
        newCan.can_name = req.body.can_name;
        newCan.can_path = 'uploads/' + req.file.filename;
        console.log(newCan.can_path);
        newCan.save(function(err, docs){
            if(err)
                throw err;
            else
                res.redirect('/auth/canUpload');
        });
    });

1 个答案:

答案 0 :(得分:1)

<td><img ng-show="{{can.can_path}}" alt="{{can.can_name}}"></td> 

<td><img ng-src="{{can.can_path}}" alt="{{can.can_name}}"></td>

试试这个。 将ng-show更改为ng-src