如何修复“我无法从函数获取值到.html”

时间:2019-01-23 04:53:59

标签: html ionic3

我想从函数中获取值,然后在.html中显示它。我用这个,但是{{this.object}}

不起作用

.html

 <ion-input type="text" placeholder="Titik" [(ngModel)]="this.object"></ion-input>

.ts

function OkE(){
     console.log(this.name);
    }
     const myObj = {
     name: 'just an object',
     status: 'idle',
    };
    this.object = OkE.apply(myObj);

1 个答案:

答案 0 :(得分:0)

尝试这样。使用属性<div id="filter-wrapper"> <ul> <li name="sortbyprice" class="current-menu-item"><a href="#">Cheapest Cars</a></li> <li name="sortbyprice" class="current-menu-item"><a href="#">Newest Cars</a></li> <li><a href="#">Car Color</a> <ul class="init" name="sortbycolor"> <li><a href="#" data-value="red">Red</a></li> <li><a href="#" data-value="black">Black</a></li> <li><a href="#" data-value="silver">Silver</a></li> </ul> </li> </ul> </div> <script> var allOptions = $(".init").children('li'); // I think you are only interested in the html content of the a (anchor) $("li[data-value] > a").on("click", function(e) { e.preventDefault(); allOptions.removeClass('selected'); $(this).addClass('selected'); let filterVal = $(this).data('value'); // do something with this ... let li = $('<li />').html( filterVal); $("ul.init").html('').append( li); // ul.init just has the value of the filter // allOptions.slideUp(); // superfluos }); </script>

value

.ts文件

<ion-input type="text" placeholder="Titik" [(ngModel)]="object" [value]="object"></ion-input>