2016-12-26 80 views
0

我正在嘗試通過單擊用戶名來獲取數據,以將用戶重定向到他的配置文件頁面上。 我試圖用做這個NG單擊像這樣:我不能讓ng-repeat數據在我的頁面上訪問另一個用戶配置文件頁面

<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); 
    }); 
}) 

在這裏,我m試圖顯示數據:

<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的的{{}}因爲我用的車把我的看法,所以在我的模塊文件我有

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

回答

0

它看起來像你應該使用{{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> 
+0

對不起我的壞我忘了提,我使用{[{my_variable}}因爲我用的車把和我的模塊文件,我使用的app.config(函數'($ interpolateProvider){$ interpolateProvider.startSymbol( '{[{').endSymbol('}]}'); });'所以在我的情況下{{}} = {[{}]} –

+0

爲什麼你一起使用Angular Js和Handlebars? Handlebars的全部屬性由Angular Js順利處理。 – xxCodexx

相關問題