重复迭代左列上的convo对象以创建选项卡,并希望在我单击选项卡时在右侧呈现适当的convo /:id。
但是我在浏览器控制台中收到此错误
Error: [$parse:syntax] Syntax Error: Token 'f6e0ce4010000' is unexpected, expecting [}] at column 17 of the expression [{id: 5595e855646f6e0ce4010000}] starting at [f6e0ce4010000}].
并且在浏览器中检查元素似乎渲染好了
<a ng-repeat="convo in convos" ui-sref="conversation.show({id: 5595e855646f6e0ce4010000})" class="ng-scope">
convo.title
我的观点
%div.collection.convo-tab-container
%a{'ui-sref'=>'conversation.show({id: {{convo._id.$oid}}})','ng-repeat'=>'convo in convos'}
convo.title
%div{class: 'col s8'}
%div{'ui-view' => true}
angularJs
var convoWidget = angular.module('convoWidget',['ngResource','templates','msgPopup','ngRoute','ui.router']);
convoWidget.config(function($stateProvider){
$stateProvider
.state('conversation.show',{
url: '/conversation/:id',
templateUrl: 'conversation-show.html',
controller: 'convoCtrl'
})
});
convoWidget.controller('convoCtrl',['$scope','$http','Conversation',function($scope,$http,Conversation){
$scope.currentUserId
$scope.convos = [] ;
$scope.defaultPicUrl = 'http://i.imgur.com/P25qqYM.png'
$scope.otherUserName = function(convo){
var other, fullName ;
if(convo.author_id.$oid === $scope.currentUserId){
other = convo.recipient
}else if(convo.recipient_id.$oid === $scope.currentUserId){
other = convo.author
}
fullName = other.firstname + ' ' + other.lastname ;
if(fullName.trim().length == 0){
return 'Anonymous User'
}
return fullName ;
}
$scope.otherUserPic = function(convo){
var picUrl ;
if(convo.author_id.$oid === $scope.currentUserId){
if(picUrl = convo.recipient.profile.avatar.small.url){
return picUrl
}else{
return $scope.defaultPicUrl
}
}else if(convo.recipient_id.$oid === $scope.currentUserId){
if(picUrl = convo.author.profile.avatar.small.url){
return picUrl
}else{
return $scope.defaultPicUrl
}
}
}
$scope.lastMsgPreview = function(convo){
var content, limit = 30 ;
content = convo.messages[convo.messages.length - 1].body
if(content.length > limit){
return content.slice(0,limit-1) + ' ' + '...' ;
}
return content ;
}
$scope.lastMsgCreatedDate = function(scope){
var msg = scope.messages[scope.messages.length - 1]
return new Date(Date.parse(msg.created_at));
}
// functions for msg directive
$scope.creatorPic = function(msg){
var picUrl ;
picUrl = msg.creator.profile.avatar.small.url;
if(picUrl){
return picUrl ;
}else{
return $scope.defaultPicUrl ;
}
}
$scope.msgCreatedDate = function(msg){
return new Date(Date.parse(msg.created_at));
}
$scope.creatorName = function(msg){
var creator, creatorId, creatorFullName
creator = msg.creator;
creatorId = creator._id.$oid;
creatorFullName = creator.firstname + ' ' + creator.lastname;
if(creatorId === $scope.currentUserId){
return 'Me' ;
}else{
var fullName = creatorFullName.trim.length == 0 ? 'Anonymous User' : creatorFullName ;
return fullName ;
}
}
$scope.msgContent = function(msg){
return msg.body
}
$scope.refresh = function(){
Conversation.getLatestConvos()
.then(function(data){
$scope.convos = data.conversations ;
console.log($scope.convos[0])
$scope.currentUserId = data.current_user ;
})
}
$scope.refresh();
}])
convoWidget.directive('convoTab',function(){
return {
restrict: 'E',
templateUrl: 'convo-tab.html',
replace: true,
scope: {
convoObj: '=',
convoId: '=',
otherUserName: '&',
otherUserPic: "&",
lastMsgPreview: '&',
lastMsgCreatedDate: '&'
}
}
})
convoWidget.directive('msg',function(){
return {
restrict: 'E',
templateUrl: 'msg.html',
replace: true,
scope: {
creatorPic: '&',
msgObj: '=',
msgCreatedDate: '&',
dateFormat: '@',
creatorName: '&',
msgContent: '&'
}
}
})
非常感谢您的阅读和任何帮助将不胜感激:D 快乐的编码!