2017-10-10 87 views
0

结合我具有其中我使用2路结合的语法来填充在一个单独的组件,像这样它的值的输入:双向具有角2

<input type="text" [(ngModel)]="this.inputValue" id="itemText"> 

而在我的index.html,我设置inputValue的值:

onSelect: function (request, response) { 
      this.inputValue = request.item; 
    } 

但是,我的输入正在更新这个新值,我错过了什么?

编辑: 的组件是设置像这样:

$('.ui.search') 
    .search({ 
    apiSettings: { 
     url: 'http://localhost:8088/Badges/{query}' 
    }, 
    onSelect: function (request, response) { 
     var urlApi = 'http://localhost:8088/Badges/Details/' + request.item; 
     this.inputValue = request.item; 
    } 
}); 

回答

0

不要:

@Component({ 
    selector: 'app-leftpane-table', 
    templateUrl: './leftpane-table.component.html' 
}) 
export class LeftpaneTableComponent implements OnInit { 
    inputValue:any; 
    constructor(private ds: DataService) { } 

    ngOnInit() {} 

而且index.html中我inputValue的设置,一旦一个项目已经从搜索结果中选择在Angular模板中使用this。您的输入应该是这样的:

<input type="text" [(ngModel)]="inputValue" id="itemText"> 

编辑:

当您在onSelect功能参考this,你不参考角度成分 - 你参考作用。你可以做的是jQuery函数之前提及this

const componentRef = this; 
$('.ui.search') 
    .search({ 
    apiSettings: { 
     url: 'http://localhost:8088/Badges/{query}' 
    }, 
    onSelect: function (request, response) { 
     var urlApi = 'http://localhost:8088/Badges/Details/' + request.item; 
     componentRef.inputValue = request.item; 
    } 
}); 

,并使用此引用,而不是this关键字。

+0

同样的问题仍然存在 – TestNInja

+0

@TestNInja你能提供更多的代码吗?没有它就很难检测到错误。 –

+0

请参阅编辑 – TestNInja