2017-06-06 39 views
0

「CH」在角1.6,傳遞行動起來(從表象組件控制器組件),我被放養在這:類型錯誤:不能使用「在」操作符來搜索喜

聊天(控制器成分)

const Chat = ['messages', function (ms) { 
    ... 
    this.sendMessage = (userInput) => { 
     ms.sendMessage(userInput) 
      .then((res) => { 
       console.log(res) 
      }) 
    } 
}] 

HTML模板:

<div class="messages"> 
    <conversation messages="ch.messages" ng-if="ch.messages" ></conversation> 
    <user-input send="ch.sendMessage(userInput)"></user-input> 
</div> 

UserInput組分(表象成分):

const UserInput = function() { 
    ... 
    this.checkAndSend =() => { 
     this.send(this.input) 
     this.input = this._clear() 
    } 
} 

angular 
    .module('chatbot-andrea') 
    .component('userInput', { 
     bindings: { 
      send: '&' 
     }, 
     ... 
    }) 

回答

0

我是在製造一個可怕的錯誤,因爲velesin.io解釋

"This is because the '&' binding is not really a callback function but an expressions, and the title and description are not function parameters but variables visible in the scope of the expression context"

因此,使用,

this.send(this.input) 

永遠是行不通的。而不是你必須使用:

this.send({userInput: this.input}) 

Codelord.net也解釋in a straightforward way

相關問題