问题
Getting the following exception with 2.2.
Was working with previous version.
Did "tns info" and all is updated to 2.2
JS: Error: Uncaught (in promise): EXCEPTION: Error in pages/listview/listview.html:12:2
JS: ORIGINAL EXCEPTION: TypeError: _this.cssClasses(...).set is not a function
JS: ORIGINAL STACKTRACE:
JS: TypeError: _this.cssClasses(...).set is not a function
JS: at /data/data/org.nativescript.test1/files/app/tns_modules/nativescript-angular/view-util.js:254:78
JS: at Array.forEach (native)
JS: at ViewUtil.setClasses (/data/data/org.nativescript.test1/files/app/tns_modules/nativescript-angular/view-util.js:254:17)
JS: at ViewUtil.setPropertyInternal (/data/data/org.nativescript.test1/files/app/tns_modules/nativescript-angular/view-util.js:189:18)
JS: at ViewUtil.setProperty (/data/data/org.nativescript.test1/files/app/tns_modules/nativescript-angular/view-util.js:181:18)
JS: at NativeScriptRenderer.setElementProperty (/data/data/org.nativescript.test1/files/app/tns_modules/nativescript-angular/renderer.js:141:23)
JS: at NativeScriptRenderer.setElementAttribute (/data/data/org.nativescript.test1/files/app/tns_modules/nativescript-angular/renderer.js:145:21)
JS: at DebugAppView._View_ListviewPage0.createInternal (ListviewPage.template.js:58:17)
JS: at DebugAppView.AppView.create (/data/data/org.nativescript.test1/files/app/tns_modules/@angular/core/src/linker/view.js:87:21)
JS: at DebugAppView.create (/data/data/org.nativescript.test1/files/app/tns_modules/@angular/core/src/linker/view.js:299:44)
JS: ERROR CONTEXT:
JS: [object Object]
回答1:
I tested this scenario with latest tns-core-modules and nativescript-angular and everything works as expected. As @Panayot.Cankov suggested you should upgrade to tns-core-modules@2.2.0
and nativescript-angular@0.3.0
. You could do that using following commands:
tns plugin remove tns-core-modules
tns plugin add tns-core-modules@2.2.0
tns plugin remove nativescript-angular
tns plugin add nativescript-angular@0.3.0
回答2:
Upgrade both the tns-core-modules@2.2.0 and nativescript-angular@0.3.0. After some refactoring we introduced the cssClasses Set on the View classes in the tns-core-modules but by unhappy coincidence the nativescript-angular was extending by monkey-patching its own cssClasses Array property on the View class. It has been resolved, but new versions of the tns-core-modules will not be compatible with old versions of the nativescript-angular.
回答3:
Make sure you upgrade your angular dependencies too, i was receiving the same error until i bumped to rc4. the below dependencies work for me now.
"@angular/common": "2.0.0-rc.4",
"@angular/compiler": "2.0.0-rc.4",
"@angular/core": "2.0.0-rc.4",
"@angular/http": "2.0.0-rc.4",
"@angular/platform-browser": "2.0.0-rc.4",
"@angular/platform-browser-dynamic": "2.0.0-rc.4",
"@angular/platform-server": "2.0.0-rc.4",
"@angular/router-deprecated": "2.0.0-rc.2",
"nativescript-angular": "^0.3.0",
"nativescript-drop-down": "^1.3.2",
"rxjs": "5.0.0-beta.6",
"tns-core-modules": "^2.2.1",
"zone.js": "^0.6.12"
来源:https://stackoverflow.com/questions/38906245/nativescript-2-2-exception