Related
I am trying to install amplify into my vue/bootstrap project. When I add this code as it is instructed in https://docs.amplify.aws/lib/auth/getting-started/q/platform/js#create-authentication-service
import Amplify, { Auth } from 'aws-amplify';
import awsconfig from './aws-exports';
Amplify.configure(awsconfig);
I receive this error:
You may need an appropriate loader to handle this file type.
| }
| replaceTraps((oldTraps) => ({
| ...oldTraps,
| get: (target, prop, receiver) => getMethod(target, prop) || oldTraps.get(target, prop, receiver),
| has: (target, prop) => !!getMethod(target, prop) || oldTraps.has(target, prop),
# ./~/#aws-amplify/datastore/lib-esm/storage/adapter/indexeddb.js 76:0-27
# ./~/#aws-amplify/datastore/lib-esm/storage/adapter/getDefaultAdapter/index.js
# ./~/#aws-amplify/datastore/lib-esm/storage/storage.js
# ./~/#aws-amplify/datastore/lib-esm/datastore/datastore.js
# ./~/#aws-amplify/datastore/lib-esm/index.js
# ./~/aws-amplify/lib-esm/index.js
# ./src/main.js
# multi ./build/dev-client ./src/main.js
I think there is problem in my package.json or I am missing something. So here is my package file:
{
"name": "frontend",
"private": true,
"scripts": {
"dev": "node build/dev-server.js",
"start": "node build/dev-server.js",
"build": "node build/build.js",
"e2e": "node test/e2e/runner.js",
"test": "npm run e2e"
},
"dependencies": {
"#aws-amplify/ui-vue": "^0.2.13",
"aws-amplify": "^3.0.23",
"axios": "^0.19.2",
"bootstrap": "^4.5.2",
"bootstrap-vue": "^2.16.0",
"jquery": "^3.5.1",
"popper.js": "^1.12.9",
"save": "^2.4.0",
"tabletojson": "^2.0.4",
"vue": "^2.6.11",
"vue-router": "^3.0.1"
},
"devDependencies": {
"#vue/cli-plugin-babel": "~4.5.0",
"#vue/cli-plugin-eslint": "~4.5.0",
"#vue/cli-plugin-router": "^4.5.3",
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-loader": "^7.1.1",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"babel-register": "^6.22.0",
"chalk": "^2.0.1",
"connect-history-api-fallback": "^1.3.0",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"cssnano": "^3.10.0",
"eventsource-polyfill": "^0.9.6",
"express": "^4.14.1",
"extract-text-webpack-plugin": "^2.0.0",
"file-loader": "^0.11.1",
"friendly-errors-webpack-plugin": "^1.1.3",
"html-webpack-plugin": "^2.28.0",
"http-proxy-middleware": "^0.17.3",
"webpack-bundle-analyzer": "^2.2.1",
"chromedriver": "^2.27.2",
"cross-spawn": "^5.0.1",
"nightwatch": "^0.9.12",
"selenium-server": "^3.0.1",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"opn": "^5.1.0",
"optimize-css-assets-webpack-plugin": "^2.0.0",
"ora": "^1.2.0",
"rimraf": "^2.6.0",
"url-loader": "^0.5.8",
"vue-loader": "^13.0.4",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.4.2",
"webpack": "^2.6.1",
"webpack-dev-middleware": "^1.10.0",
"webpack-hot-middleware": "^2.18.0",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 4.0.0",
"npm": ">= 3.0.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
Thank you in advance!
I had the same problem, but I resolved it installing amplify version 1.1.4.
npm install aws-amplify#^1.1.4
I hope it is useful to you.
I'm having THE SAME PROBLEM! I'm also learning VueJS with Academind's Max on Udemy and I'm trying to use Amplify cuz firebase gave me other more confusing errors (he didn't get any and I follow him step by step...)
I hope that someone answers either your or my question for this because I'm really stuck and upset I can't keep practicing now :(
I've been trying for a couple of days now to get some tests to run.
I've two environments, one very "empty" and another with a full project.
The 'empty' one does run a very simple test (but doesn't contain the Person object that is unable to be constructed in the full project).
I migrated the full project to a very similar environment in terms of installed dev packages, karma, jasmine versions and such. I also copied the tsconfig.json, karma.conf files across. Those are below.
For the life of me I cannot figure out why the karma tests will not run.
With previous versions of Karma I would get an error along the lines of 'scheduler_person.b' is not a constructor.
Digging a little deeper, it's failing on this line of test.store.ts:
let neil: Person = new Person("Neil Clayton");
the constructor of this object is:
constructor(name: string = "put name here") {
super();
this.name = name;
this.primary_roles = new Map<Role, number>();
this.specific_roles = new Map<string, Array<Role>>();
this.secondary_action_list = [];
this.condition_rules = [];
this.unavailable = [];
this.prefs = new SchedulePrefs();
}
So, the Person class has a constructor, and this code does run within the app itself.
I have since upgraded all of karma/jasmine and the error now changes to:
VM105 karma-test-shim.js:629 Uncaught TypeError: $f.b is not a constructor
Looking at the generated code, it's essentially exactly the same inability to call a constructor.
I feel I must be doing something very simple, very stupid, but I cannot see it.
Any ideas?
(btw: this project is at https://github.com/scornflake/scheduler)
tsconfig.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noImplicitThis": true,
"lib": [
"dom",
"es2015",
"esnext.asynciterable"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"src/**/*.spec.ts"
],
"typeAcquisition": {
"enable": true,
"include": [
"./src/common/fix.broken.gapi.types.d.ts"
]
},
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
karma.config.json
const webpackConfig = require('./webpack.test.js');
module.exports = function (config) {
const _config = {
basePath: '',
frameworks: [
'jasmine'
// 'jasmine-matchers'
],
files: [
{
pattern: './karma-test-shim.js',
watched: true
}
],
preprocessors: {
'./karma-test-shim.js': ['webpack', 'sourcemap']
},
webpack: webpackConfig,
webpackMiddleware: {
stats: 'errors-only'
},
webpackServer: {
noInfo: true
},
browserConsoleLogOptions: {
level: 'log',
format: '%b %T: %m',
terminal: true
},
// reporters: ['kjhtml', 'dots'],
reporters: ['dots'],
// reporters: ['kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
};
config.set(_config);
};
karma-test-shim.js
Error.stackTraceLimit = Infinity;
require('core-js/es6');
require('core-js/es7/reflect');
require('zone.js/dist/zone');
require('zone.js/dist/long-stack-trace-zone');
require('zone.js/dist/proxy');
require('zone.js/dist/sync-test');
require('zone.js/dist/jasmine-patch');
require('zone.js/dist/async-test');
require('zone.js/dist/fake-async-test');
var appContext = require.context('../src', true, /\.spec\.ts/);
appContext.keys().forEach(appContext);
var testing = require('#angular/core/testing');
var browser = require('#angular/platform-browser-dynamic/testing');
testing.TestBed.initTestEnvironment(browser.BrowserDynamicTestingModule, browser.platformBrowserDynamicTesting());
package.json
{
"name": "scheduler",
"version": "0.0.1",
"author": "Neil Clayton",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build --copy ./config/copy.config.js",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build --copy ./config/copy.config.js",
"ionic:serve": "ionic-app-scripts serve --copy ./config/copy.config.js",
"test-coverage": "ng test --code-coverage",
"test": "ng test"
},
"dependencies": {
"#angular/common": "5.0.3",
"#angular/compiler": "5.0.3",
"#angular/compiler-cli": "5.0.3",
"#angular/core": "5.0.3",
"#angular/forms": "5.0.3",
"#angular/http": "5.0.3",
"#angular/platform-browser": "5.0.3",
"#angular/platform-browser-dynamic": "5.0.3",
"#ionic-native/core": "4.3.2",
"#ionic-native/splash-screen": "4.3.2",
"#ionic-native/status-bar": "4.3.2",
"#ionic/storage": "2.1.3",
"#types/gapi": "^0.0.35",
"#types/gapi.auth2": "^0.0.47",
"#types/gapi.client": "^1.0.0",
"#types/gapi.client.drive": "^3.0.1",
"#types/gapi.client.sheets": "^4.0.0",
"angular-pipes": "^6.5.3",
"apollo-angular": "^1.0.1",
"apollo-angular-link-http": "^1.0.2",
"apollo-cache-inmemory": "^1.1.12",
"apollo-client": "^2.2.8",
"apollo-link": "^1.2.2",
"cordova-browser": "5.0.1",
"cordova-plugin-device": "^1.1.4",
"cordova-plugin-ionic-webview": "^1.1.16",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-whitelist": "^1.3.1",
"file-saver": "^1.3.8",
"google-auth-library": "^1.4.0",
"googleapis": "^28.1.0",
"graphql": "^0.13.2",
"graphql-tag": "^2.8.0",
"ionic-angular": "3.9.2",
"ionic-configuration-service": "^6.0.0",
"ionic-logging-service": "^5.0.0",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"json2csv": "^3.11.5",
"lodash": "^4.17.4",
"mobx": "^4.1.1",
"mobx-angular": "^3.0.1",
"moment": "^2.20.1",
"ng-circle-progress": "^0.9.9",
"rxjs": "5.5.2",
"short-unique-id": "^1.1.0",
"sw-toolbox": "3.6.0",
"to-case": "^2.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"#ionic/app-scripts": "3.1.6",
"#types/jasmine": "2.8.4",
"#types/node": "8.5.8",
"angular2-template-loader": "^0.6.2",
"file-save": "^0.2.0",
"html-loader": "^0.5.5",
"jasmine-core": "3.1.0",
"jasmine-expect": "^3.8.3",
"jasmine-spec-reporter": "^4.1.0",
"karma": "^2.0.2",
"karma-chrome-launcher": "^2.2.0",
"karma-jasmine": "^1.1.1",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^3.0.0",
"null-loader": "^0.1.1",
"protractor": "5.3.0",
"ts-loader": "^4.2.0",
"ts-node": "4.1.0",
"typescript": "2.4.2",
"webpack": "^4.6.0"
},
"description": "Scheduler",
"cordova": {
"plugins": {
"ionic-plugin-keyboard": {},
"cordova-plugin-whitelist": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {}
},
"platforms": [
"browser"
]
}
}
Finally, some pics of the browser errors:
In src/providers/store/test.store.ts you need to move all of your global constants (and subsequent method calls) into the SetupStore method of the NPBCStoreConstruction class. When I do this I can run the test suite properly.
The cause of issue is that when Webpack/Typescript/something compiles everything, it picks an arbitrary order to include all the files and if you look at the generated code you can see that the global invocation of the person Person constructor happens before it is defined.
I raised a similar question two days back, but this time I am getting the same error when I run the code in an actual device or simulator. On a regular browser it works fine.
Here is my app.component.ts code:
import { Component, ViewChild } from '#angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '#ionic-native/status-bar';
import { SplashScreen } from '#ionic-native/splash-screen';
import { HomePage } from '../pages/home/home';
import { LoginPage } from '../pages/login/login';
import {NativeStorage} from '#ionic-native/native-storage';
import { NavController } from 'ionic-angular';
#Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = LoginPage;
#ViewChild('navApp') nav : NavController;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, private nativeStorage: NativeStorage,) {
platform.ready().then(() => {
this.nativeStorage.getItem('userExists').then((data)=>{
this.nav.push(HomePage);
console.log(data.userExists);
},(error)=>{
console.log("No Data in Local Storage");
this.nav.push(LoginPage);
})
statusBar.styleDefault();
splashScreen.hide();
});
}
}
This is my app.html
<ion-nav #navApp [root]="rootPage"></ion-nav>
This is my version info
global packages:
#ionic/cli-utils : 1.2.0
Cordova CLI : 7.0.1
Ionic CLI : 3.2.0
local packages:
#ionic/app-scripts : 1.3.7
#ionic/cli-plugin-cordova : 1.2.1
#ionic/cli-plugin-ionic-angular : 1.2.0
Cordova Platforms : android 6.2.3
Ionic Framework : ionic-angular 3.2.1
System:
Node : v6.10.2
OS : Windows 10
Xcode : not installed
ios-deploy : not installed
ios-sim : not installed
Package.json:
{
"name": "myapp",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"#angular/common": "4.1.0",
"#angular/compiler": "4.1.0",
"#angular/compiler-cli": "4.1.0",
"#angular/core": "4.1.0",
"#angular/forms": "4.1.0",
"#angular/http": "4.1.0",
"#angular/platform-browser": "4.1.0",
"#angular/platform-browser-dynamic": "4.1.0",
"#ionic-native/core": "3.7.0",
"#ionic-native/facebook": "^3.10.2",
"#ionic-native/native-storage": "^3.10.3",
"#ionic-native/splash-screen": "3.7.0",
"#ionic-native/status-bar": "3.7.0",
"#ionic/storage": "2.0.1",
"cordova-android": "^6.2.3",
"cordova-plugin-console": "^1.0.5",
"cordova-plugin-device": "^1.1.4",
"cordova-plugin-facebook4": "^1.9.0",
"cordova-plugin-nativestorage": "^2.2.2",
"cordova-plugin-splashscreen": "^4.0.3",
"cordova-plugin-statusbar": "^2.2.2",
"cordova-plugin-whitelist": "^1.3.1",
"ionic-angular": "3.2.1",
"ionic-native": "^2.5.1",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"rxjs": "5.1.1",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.10"
},
"devDependencies": {
"#ionic/app-scripts": "1.3.7",
"#ionic/cli-plugin-cordova": "^1.2.1",
"#ionic/cli-plugin-ionic-angular": "^1.2.0",
"typescript": "2.2.1"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-console": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-whitelist": {},
"ionic-plugin-keyboard": {},
"cordova-plugin-facebook4": {
"APP_ID": "305938313175123",
"APP_NAME": "myapp"
},
"cordova-plugin-nativestorage": {}
},
"platforms": [
"android"
]
}
}
Updating to the latest ionic release 3.3.0 solved the issue!
Why dont you just change the value of rootPage instead of making a push?
You have the variable
rootPage:any = LoginPage;
So by default your homepage will be LoginPage. When you check in your localstorage if the nickname exists, instead of pushing a page, use
this.rootPage = NameofYourPageHere.
That should work.
Recently I updated Angular from 2.0.3 to 2.4.3 and Angular-CLI from 1.0.0-beta.21 to 1.0.0-beta.25.5
After upgrade my unit tests stop working. Below you can find test file, configuration files and test results. Do you have any idea what can be wrong with it? Thanks
test result
$ npm test -- --watch=false
> portal#0.0.0 test /Users/artur/Sites/portal
> ng test "--watch=false"
19 01 2017 08:22:52.703:WARN [karma]: Port 9879 in use
19 01 2017 08:22:52.705:INFO [karma]: Karma v1.4.0 server started at http://0.0.0.0:9880/
19 01 2017 08:22:52.705:INFO [launcher]: Launching browser Chrome with unlimited concurrency
19 01 2017 08:22:52.726:INFO [launcher]: Starting browser Chrome
19 01 2017 08:22:55.619:INFO [Chrome 55.0.2883 (Mac OS X 10.12.2)]: Connected on socket XIi2HWa92rY4uvNvAAAA with id 35735618
Chrome 55.0.2883 (Mac OS X 10.12.2): Executed 0 of 0 ERROR (0.004 secs / 0 secs)
npm ERR! Test failed. See above for more details.
banner.component.spec.ts
/* tslint:disable:no-unused-variable */
import { Component } from '#angular/core';
import { TestBed, async } from '#angular/core/testing';
import { BannerComponent } from './banner.component';
import { RouterTestingModule } from '#angular/router/testing';
#Component({
template: ''
})
class DummyComponent {}
describe('Component: Banner', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
DummyComponent,
BannerComponent
],
imports: [
RouterTestingModule.withRoutes([
{ path: '', component: DummyComponent }
])
],
providers: []
});
});
it('should create an instance', async(() => {
let fixture = TestBed.createComponent(BannerComponent);
let component = fixture.debugElement.componentInstance;
expect(component).toBeTruthy();
}));
});
banner.component.ts
import { Component, OnInit } from '#angular/core';
#Component({
selector: 'app-banner',
templateUrl: './banner.component.html',
styleUrls: ['./banner.component.scss'],
styles: [".banner >>> lp-svg svg path { fill: #fcfcfc; }"]
})
export class BannerComponent {}
package.json
{
"name": "portal",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ngc": "./node_modules/.bin/ngc -p ./src",
"start": "./node_modules/.bin/ng serve --host 0.0.0.0 --port 4000",
"build.dev": "./node_modules/.bin/ng build --bh /portal/",
"build.dev.watch": "./node_modules/.bin/ng build --bh /portal/ --watch true",
"build.prod": "./node_modules/.bin/ng build --bh /portal/ --prod --env=prod",
"build.prod.watch": "./node_modules/.bin/ng build --bh /portal/ --prod --env=prod",
"serve.prod": "node lp-server.js",
"lint": "tslint \"src/**/*.ts\"",
"test": "./node_modules/.bin/ng test",
"e2e": "./protractor.sh",
"copy.support-page": "./node_modules/.bin/copyfiles -u 1 ./src/support.html ./dist"
},
"private": true,
"dependencies": {
"#angular/common": "^2.4.3",
"#angular/compiler": "^2.4.3",
"#angular/compiler-cli": "^2.4.3",
"#angular/core": "^2.4.3",
"#angular/forms": "^2.4.3",
"#angular/http": "^2.4.3",
"#angular/platform-browser": "^2.4.3",
"#angular/platform-browser-dynamic": "^2.4.3",
"#angular/platform-server": "^2.4.3",
"#angular/router": "^3.4.3",
"copyfiles": "1.0.0",
"core-js": "2.4.1",
"jquery": "2.2.3",
"perfect-scrollbar": "~0.6.10",
"rxjs": "^5.0.3",
"ts-helpers": "1.1.1",
"typescript": "2.0.2",
"underscore": "1.8.3",
"zone.js": "0.6.23"
},
"devDependencies": {
"#types/jasmine": "^2.5.41",
"angular-cli": "^1.0.0-beta.25.5",
"codelyzer": "^2.0.0-beta.4",
"jasmine-core": "^2.5.2",
"jasmine-spec-reporter": "^3.2.0",
"karma": "^1.4.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.1.0",
"karma-mocha-reporter": "^2.2.1",
"karma-phantomjs-launcher": "^1.0.2",
"karma-remap-istanbul": "^0.4.0",
"live-server": "1.1.0",
"protractor": "^5.0.0",
"ts-node": "1.2.1",
"tslint": "3.13.0"
}
}
karma.conf.js
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', 'angular-cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-phantomjs-launcher'),
require('karma-remap-istanbul'),
require('angular-cli/plugins/karma'),
require('karma-mocha-reporter')
],
files: [
{ pattern: 'src/test.ts', watched: false },
{ pattern: 'src/assets/img/*', watched: false, included: false, served: true, nocache: false }
],
proxies: {
'/portal/assets/img/': '/base/src/assets/img/'
},
preprocessors: {
'./src/test.ts': ['angular-cli']
},
remapIstanbulReporter: {
reports: {
html: 'coverage',
lcovonly: './coverage/coverage.lcov'
}
},
angularCli: {
config: './angular-cli.json',
environment: 'dev'
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'karma-remap-istanbul']
: ['progress'],
port: 9879,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
browserConsoleLogOptions: {
level: 'debug',
format: '%b %T: %m',
terminal: true
},
customLaunchers: {
'PhantomJS_custom': {
base: 'PhantomJS',
options: {
windowName: 'my-window',
settings: {
webSecurityEnabled: false
},
},
flags: ['--load-images=true'],
debug: true
}
},
phantomjsLauncher: {
// Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom)
exitOnResourceError: true
}
});
};
angular-cli.json
{
"project": {
"version": "1.0.0-beta.25.5",
"name": "ui-lender-portal-v2"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": ["assets"],
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "lp",
"mobile": false,
"styles": [
"styles.scss",
"../node_modules/perfect-scrollbar/dist/css/perfect-scrollbar.min.css"
],
"scripts": [
"../node_modules/underscore/underscore.js",
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/perfect-scrollbar/dist/js/perfect-scrollbar.js",
"./libs/jquery-ui/jquery-ui.min.js",
"./libs/jquery-mobile/jquery.mobile.custom.min.js",
"./libs/slick/slick.js"
],
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "scss",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}
Finally I created new project with Angular-CLI and copied source files from my project. This helps.
I struggle http client works, firstly i tried http module but when i searched examples, I saw they did with jsonp. Briefly, when i tried this jsonp i get this error :
Error: Uncaught (in promise): Error: Error in ./MusteriComponent class MusteriComponent **- inline template:0:0 caused by: No provider for Jsonp!**
Stack trace:
resolvePromise#http://localhost:4200/main.bundle.js:101640:31
makeResolver/<#http://localhost:4200/main.bundle.js:101617:13
Zone$1</ZoneDelegate</ZoneDelegate.prototype.invoke#http://localhost:4200/main.bundle.js:101414:19
NgZoneImpl/this.inner<.onInvoke#http://localhost:4200/main.bundle.js:65487:28
Zone$1</ZoneDelegate</ZoneDelegate.prototype.invoke#http://localhost:4200/main.bundle.js:101413:19
Zone$1</Zone</Zone.prototype.run#http://localhost:4200/main.bundle.js:101307:24
scheduleResolveOrReject/<#http://localhost:4200/main.bundle.js:101673:52
Zone$1</ZoneDelegate</ZoneDelegate.prototype.invokeTask#http://localhost:4200/main.bundle.js:101447:23
NgZoneImpl/this.inner<.onInvokeTask#http://localhost:4200/main.bundle.js:65478:28
Zone$1</ZoneDelegate</ZoneDelegate.prototype.invokeTask#http://localhost:4200/main.bundle.js:101446:23
Zone$1</Zone</Zone.prototype.runTask#http://localhost:4200/main.bundle.js:101347:28
drainMicroTaskQueue#http://localhost:4200/main.bundle.js:101579:25
ZoneTask/this.invoke#http://localhost:4200/main.bundle.js:101519:25
app-module
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { FormsModule } from '#angular/forms';
import { HttpModule} from '#angular/http';
import { AppComponent } from './app.component';
import { MainModule } from './main/main.module'
import { routing,
appRoutingProviders } from './app.routing';
import { LoginComponent } from './login/login.component';
import {InMemoryWebApiModule} from "angular2-in-memory-web-api";
import {CosmoData} from "./cosmo-data"
#NgModule({
declarations: [
LoginComponent,
AppComponent
],
imports: [
MainModule,
BrowserModule,
FormsModule,
HttpModule,
routing,
InMemoryWebApiModule.forRoot(CosmoData)
],
providers: [
appRoutingProviders
],
bootstrap: [AppComponent]
})
export class AppModule { }
package-json
{
"name": "cosmo-client",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"start": "ng serve",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"#angular/common": "2.0.0",
"#angular/compiler": "2.0.0",
"#angular/core": "2.0.0",
"#angular/forms": "2.0.0",
"#angular/http": "2.0.0",
"#angular/platform-browser": "2.0.0",
"#angular/platform-browser-dynamic": "2.0.0",
"#angular/router": "3.0.0",
"angular2-in-memory-web-api": "0.0.20",
"core-js": "^2.4.1",
"primeng": "^1.0.0-beta.16",
"rxjs": "5.0.0-beta.12",
"ts-helpers": "^1.1.1",
"zone.js": "^0.6.23"
},
"devDependencies": {
"#types/jasmine": "^2.2.30",
"angular-cli": "1.0.0-beta.14",
"codelyzer": "~0.0.26",
"jasmine-core": "2.4.1",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "4.0.5",
"ts-node": "1.2.1",
"tslint": "3.13.0",
"typescript": "2.0.2",
"webpack": "2.1.0-beta.22"
}
}
gib-service
import { Injectable } from '#angular/core';
import {Observable} from "rxjs";
import {Response,Http,Jsonp} from "#angular/http";
import any = jasmine.any;
#Injectable()
export class GibService {
constructor(private http:Http,private jsonp:Jsonp) { }
items:any;
private handleError(err) {
console.log(err);
return Observable.throw(err);
}
search ():Observable<any> {
return this.jsonp.get('http://gturnquist-quoters.cfapps.io/api/random')
.map(resp => resp.json()).catch(this.handleError);
}
}
MusteriTanimlama
import {Component, OnInit} from '#angular/core';
import {GibService} from "./gib.service";
import {MusteriTanimlama} from "./musteritanimlama";
import { Observable } from 'rxjs/Observable';
import any = jasmine.any;
#Component({
selector: 'cosmo-musteritanimlama',
templateUrl: './musteritanimlama.component.html',
styleUrls: ['./musteritanimlama.component.css'],
providers: [GibService]
})
export class MusteritanimlamaComponent {
constructor(private gibservice: GibService) {
}
search () {
this.gibservice.search().subscribe(m=>{
console.log("search");
console.log(m);
});
}
Thank you for answer
You need add the JsonpModule to imports:
#NgModule({
declarations: [
LoginComponent,
AppComponent
],
imports: [
MainModule,
BrowserModule,
FormsModule,
HttpModule,
JsonpModule, // <<<<===
routing,
InMemoryWebApiModule.forRoot(CosmoData)
],
providers: [
appRoutingProviders
],
bootstrap: [AppComponent]
})
export class AppModule { }