【问题标题】:I can't get ng-repeat data to go on my page for visiting another user profile page我无法在我的页面上获取 ng-repeat 数据以访问另一个用户个人资料页面
【发布时间】:2016-12-26 21:22:31
【问题描述】:

我正在尝试通过单击用户名来获取数据,以便在用户的个人资料页面上重定向用户。 我正在尝试像这样使用 ng-click 来做到这一点:

<p style="font-size:11px; color: grey; " ng-click="seeProfile(gterest);changelocation();"><b>{[{gterest.author}]}</b></p>

我的两个控制器功能:

$scope.seeProfile = function (gterest) {
        console.log(gterest);
        var user = gterest.author;
        $http.post('/userProfile/', {user: user}).then(function (results) {
            console.log(results);
            $scope.userProfileList = results.data;
        })
    };

    $scope.changelocation = function () {
        $window.location.href = '/userProfile/';
    }

我的服务器功能:

router.post('/', function (req, res) {
    var user = req.body.user;
    console.log(user);
    mongoose.model('Gterest').find({"author": user},function(err, gterests){
        if(err) console.log(err);
        console.log(gterests)
        res.json(gterests);
    });
})

我在这里尝试显示数据:

<div ng-controller="allGterest">
    <div masonry>
        <div class="masonry-brick pinterest" ng-repeat="user in userProfileList">
            <img ng-src="{[{user.image}]}" alt="aaa" style="width: 238px;">
            <p style="font-size:11px; color: grey; "><b>{[{user.author}]}</b></p>
            <p style="margin-top: 5px;"  ><b>{[{gterest.title}]}</b></p>
            <button class="btn btn-danger btn-xs" style="margin-bottom: 2px;"><span class="glyphicon glyphicon-heart"></span></button>
        </div>
    </div>
</div>

这并没有给我任何错误,但我的屏幕是空白的,我不知道该怎么办。 请帮忙!谢谢!

编辑: 我正在使用 {[{}]} insted of {{}} 因为我使用把手作为我的视图,所以在我的模块文件中我有

app.config(function ($interpolateProvider) {
    $interpolateProvider.startSymbol('{[{').endSymbol('}]}');
});

【问题讨论】:

    标签: angularjs node.js mongodb


    【解决方案1】:

    看起来您应该使用 {{your_varibale}} 而不是 {[{your_varibale}]} 。以下是更新后的代码。

    <div ng-controller="allGterest">
        <div masonry>
            <div class="masonry-brick pinterest" ng-repeat="user in userProfileList">
                <img ng-src="{{user.image}}" alt="aaa" style="width: 238px;">
                <p style="font-size:11px; color: grey; "><b>{{user.author}}</b></p>
                <p style="margin-top: 5px;"  ><b>{{gterest.title}}</b></p>
                <button class="btn btn-danger btn-xs" style="margin-bottom: 2px;"><span class="glyphicon glyphicon-heart"></span></button>
            </div>
        </div>
    </div>
    

    【讨论】:

    • 对不起,我忘了提,我使用 {[{my_variable}} 因为我使用把手,并且在我的模块文件中我使用 app.config(function ($interpolateProvider) { $interpolateProvider.startSymbol('{[{').endSymbol('}]}'); }); 所以在我的情况下 {{} } = {[{}]}
    • 你为什么要同时使用 Angular Js 和 Handlebars ? Handlebars 的整个属性都由 Angular Js 顺利处理。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 2020-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多