2016-12-14 24 views
0

我正在使用angularJS和node.js 這裏發生了一個問題,即'ng樣式'三元條件總是導致false,而它必須是true。 這裏是我的代碼:ng樣式三元條件總是導致虛假

  <div class="msg-single" 
       ng-repeat="message in messages" 
       ng-style="{'cursor': msessage.toid === socketId ? 'not-allowed':'pointer'}"> 
       {{message.fromid === socketId ? 'You': message.name }} : {{ message.msg }} 
      </div> 

在上面的代碼中,NG-樣式所得發送者插座以及接收器插座(指針)上假。 而在下一行,message.fromid === socketId它工作正常意味着它在相同的socketId爲true,但在發件人正在發送消息的另一個套接字ID爲false。

,相關的.js代碼:

socket.on('getMsg', (data) => { 

      socket.broadcast.to(data.toid).emit('sendMsg',{ 
       msg:data.msg, 
       name:data.name, 
       fromid:data.fromid, 
       toid:data.toid 
      }); 
      socket.emit('sendMsg',{ 
       msg:data.msg, 
       name:data.name, 
       fromid:data.fromid, 
       toid:data.toid 
      }); 

     }); 

socket.on('sendMsg', (data) => { 
    //console.log('send'); 
      $scope.messages.push(data); 
     }); 

您能否提供我什麼可能是可能的原因?和解決方案。

+1

msessage.toid是錯誤的 –

回答

1

我不知道爲什麼,但我覺得你可以試試這個:

ng-style="{message.toid === socketId} && {'cursor': 'not-allowed'} || {'cursor':'pointer'}" 
0

我認爲這應該爲你工作:

ng-style="message.toid === socketId ? {'cursor':'not-allowed'} : {'cursor':'pointer'}" 

或者:

ng-style="{{message.toid === socketId}} ? {'cursor':'not-allowed'} : {'cursor':'pointer'}"