1 import {ChangeDetectorRef} from "angular2/core"; //引入ChangeDetectorRef定义 2 constructor(public changeDetectorRef:ChangeDetectorRef) { //注入当前组件的ChangeDetectore 3 this.cd = cd; 4 this.records = []; 5 } 6 barcodeScanner() { 7 var self = this; 8 cordova.plugins.barcodeScanner.scan(function (result) { 9 if (!result.cancelled) { 10 self.records.unshift(result); 11 alert(self.records.length); 12 self.changeDetectorRef.markForCheck(); // 通知框架进行变化检查/Change Detection 13 } 14 }, function (error) { 15 alert("发生了一个错误:" + error); 16 }); 17 }
原文地址:https://www.cnblogs.com/lxzzlxz5/p/12149243.html
时间: 2024-11-20 05:06:44