Can't bind to 'lazyLoad' since it isn't a known property of 'img' tag in ionic3? - ionic2

I have got above error after reload the page in ionic3 after apply lazy Loading on images ?
Steps I took:
Run Npm:
npm install ng2-lazyload-image --save`
Imported into my component:
import { LazyLoadImageDirective } from 'ng2-lazyload-image';
In my template:
In above template userProduct.ImageCollection is array of dynamic image that is get from the Fire-store but i got above error after load page.
Maybe there’s something I’m overlooking, but I can’t seem to see what it is.
import { BrowserModule } from '#angular/platform-browser';
import { ErrorHandler, NgModule, enableProdMode } from '#angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { TranslateModule, TranslateLoader } from '#ngx-translate/core';
import { LazyLoadImageModule } from 'ng2-lazyload-image';
#NgModule({
declarations: [
MyApp,
ImageSlider
],
imports: [
BrowserModule,
LazyLoadImageModule,
IonicModule.forRoot(MyApp),
IonicStorageModule.forRoot(),
TranslateModule.forRoot({
loader : {
provide : TranslateLoader,
useFactory : (createTranslateLoader),
deps : [HttpClient]
}
})
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
ImageSlider,
],
providers: [
StatusBar,
SplashScreen,
Clipboard,
{provide: ErrorHandler , useClass: IonicErrorHandler},
Network
]
})
export class AppModule {}
enableProdMode();
export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
<img [defaultImage]="assets/imgs/product_defaultImg.png" [lazyLoad]="userProduct.ImageCollection[0].url" [offset]="offset">

Related

Ionic 2 Super Tabs not showing properly in browsers

I'm using Ionic CLI v3.5.0 and Ionic2 Super Tabs v3.0.2
But the tabs are not displaying properly. On clicking the tabs, page changes but they are not displaying.
Here is my app.module.ts. I have added SuperTabsModule.forRoot() as indicated in the docs.
import { BrowserModule } from '#angular/platform-browser';
import { ErrorHandler, NgModule } from '#angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { SplashScreen } from '#ionic-native/splash-screen';
import { StatusBar } from '#ionic-native/status-bar';
import { SuperTabsController} from 'ionic2-super-tabs';
import { MyApp } from './app.component';
import { ExplorePage } from '../pages/explore/explore';
import { SuperTabsModule } from 'ionic2-super-tabs';
import { CoachingsPage } from '../pages/coachings/coachings';
import { TutorsPage } from '../pages/tutors/tutors';
#NgModule({
declarations: [
MyApp,
ExplorePage,
CoachingsPage,
TutorsPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
SuperTabsModule.forRoot(),
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
ExplorePage,
CoachingsPage,
TutorsPage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
This is my tab.ts file. Here my pages doesn't use lazy loading so I haven't added SuperTabsModule here. I had added it but that didn't work.
import { Component } from '#angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { CoachingsPage } from '../coachings/coachings';
import { TutorsPage } from '../tutors/tutors';
/**
* Generated class for the ExplorePage page.
*
* See http://ionicframework.com/docs/components/#navigation for more info
* on Ionic pages and navigation.
*/
#IonicPage()
#Component({
selector: 'page-explore',
templateUrl: 'explore.html',
})
export class ExplorePage {
tab1Root:any = CoachingsPage;
tab2Root:any = TutorsPage;
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad ExplorePage');
}
}
Here's the tabs.html file:
<super-tabs>
<super-tab [root]="tab1Root" title="Top Tutors"></super-tab>
<super-tab [root]="tab2Root" title="Top Coaching"></super-tab>
</super-tabs>
It has been a while but I had the same problem you have and I finally found that super-tabs CSS wasn't loaded.
You can try to retrieve the CSS and put it in one of your file as a test.

Module has no exported module named PeopleService - Ionic

I have been folllowing the ionic tutorial:
10 Minutes with Ionic 2: Calling an API
Typescript Error
Module '"C:/Users/grace/imaginemai/client/apiApp/src/providers/people->service/people-service"' has no exported member 'PeopleSevice'.
C:/Users/grace/imaginemai/client/apiApp/src/pages/home/home.ts
import { NavController } from 'ionic-angular';
import {PeopleSevice} from >'C:\Users\grace\imaginemai\client\apiApp\src\providers\people-> >service\people-service';
I am not sure what I am doing wrong. I noticed that there were possible errors with the original tutorial so I made some amendments as per a correction posted in the comments: https://github.com/ah3243/ionic2ApiExample/blob/master/src/providers/people-search.ts
I am still having issues - I've followed the tutorial but used my own API from a blog I am developing with Django. So although the ionic app is called peopleservice, I am expecting it to produce blog posts. The code is pasted below. Please could someone tell me what I am doing wrong.
Thanks in advance.
people-service.ts:
import { Injectable } from '#angular/core';
import { Http } from '#angular/http';
import 'rxjs/add/operator/map';
/*
Generated class for the PeopleServiceProvider provider.
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
#Injectable()
export class PeopleService {
data1: any;
constructor(public http: Http) {
console.log('Hello PeopleService Provider');
}
load() {
if (this.data1) {
return Promise.resolve(this.data1);
}
//dont have the data yet
return new Promise(resolve => {
this.http.get('localhost:8000/posts/')
.map(res => res.json())
.subscribe(data => {
this.data1 = data.results;
resolve(this.data1);
});
});
}
}
home.ts:
import { Component } from '#angular/core';
import { NavController } from 'ionic-angular';
import {PeopleSevice} from 'C:\\Users\\grace\\imaginemai\\client\\apiApp\\src\\providers\\people-service\\people-service';
#Component({
selector: 'page-home',
templateUrl: 'home.html',
providers: [PeopleSevice]
})
export class HomePage {
public posts: any;
constructor(public navCtrl: NavController, public peopleService: PeopleService) {
this.loadPosts();
}
loadPosts() {
this.PeopleService.load()
.then(data1 => {
this.posts = data1;
})
}
}
app.module.ts:
import { NgModule, ErrorHandler } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';
import { AboutPage } from '../pages/about/about';
import { ContactPage } from '../pages/contact/contact';
import { HomePage } from '../pages/home/home';
import { TabsPage } from '../pages/tabs/tabs';
import { StatusBar } from '#ionic-native/status-bar';
import { SplashScreen } from '#ionic-native/splash-screen';
/*import { PeopleService } from 'C:\\Users\\grace\\imaginemai\\client\\apiApp\\src\\providers\\people-service\\people-service';*/
#NgModule({
declarations: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
AboutPage,
ContactPage,
HomePage,
TabsPage
],
providers: [
/*StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
PeopleService*/
]
})
export class AppModule {}
app.component.ts:
import { Component } from '#angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '#ionic-native/status-bar';
import { SplashScreen } from '#ionic-native/splash-screen';
import { TabsPage } from '../pages/tabs/tabs';
import { PeopleService } from 'C:\\Users\\grace\\imaginemai\\client\\apiApp\\src\\providers\\people-service\\people-service';
#Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage:any = TabsPage;
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
});
}
}
home.html:
<ion-header>
<ion-navbar *navbar>
<ion-title>
Home
</ion-title>
</ion-navbar>
</ion-header>
<ion-content class="home">
<ion-list>
<ion-item *ngFor="let post of posts">
<h2>{{post.title}}</h2>
<p>{{post.text}}</p>
</ion-item>
</ion-list>
</ion-content>
folder structure:
blog
>client
>apiApp
>src
>app
>app.component.ts
>app.html
>app.module.ts
>app.scss
>main.ts
>pages
>providers
>people-service
>people-service.ts
You have to use relative paths for importing.
import {PeopleSevice} from 'C:\\Users\\grace\\imaginemai\\client\\apiApp\\src\\providers\\people-service\\people-service';
This kind of absolute path will not work.
Try:
import {PeopleSevice} from '../../providers/people-service/people-service';
This is the relative path from the current file.

Error in Angular 4.x Karma test "No Provider for FocusTrapFactory"

I have a small Angular v4.x using Angluar Material 2.x
It has a modal (using MdDialog) login component - and pretty much nothing else.
All my tests are failing with:
Failed: No provider for FocusTrapFactory! at injectionError
(http://localhost:9876/base/src/test.ts?31c6eb17e2414560f8e07e35e9c56bebb408ba58:2074:86)
[angular]
at noProviderError (http://localhost:9876/base/src/test.ts?31c6eb17e2414560f8e07e35e9c56bebb408ba58:2112:12)
[angular] ...
my login.component.spec.ts is
import { async, ComponentFixture, TestBed } from '#angular/core/testing';
import { FormsModule } from '#angular/forms';
import { RouterTestingModule } from '#angular/router/testing';
import { BrowserDynamicTestingModule } from '#angular/platform-browser-dynamic/testing';
import { NoopAnimationsModule } from '#angular/platform-browser/animations';
import { MdDialog, MdDialogContainer, MdInputContainer, OVERLAY_PROVIDERS } from '#angular/material';
import { HttpModule } from '#angular/http';
import { AuthenticationService } from '../shared/servicesIndex';
import { LoginComponent } from './login.component';
describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
beforeEach(async(() => {
TestBed.overrideModule(BrowserDynamicTestingModule, {
set: {
entryComponents: [MdDialogContainer]
}
});
TestBed.configureTestingModule(
{
imports: [
FormsModule,
RouterTestingModule,
HttpModule,
NoopAnimationsModule
],
declarations: [
LoginComponent,
MdInputContainer,
MdDialogContainer
],
providers: [
MdDialog,
OVERLAY_PROVIDERS,
AuthenticationService
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Logic tells me to import FocusTrapFactory and add it to my list of providers - but I can't find it to import it!
I'm at a loss. My Google-fu is fu.
Just needed to add import { MaterialModule } from '#angular/material'; then add MaterialModule to the imports array in my app.component.spec.ts.
You should add the right packages for the material components. Unfortunately MaterialModule is marked depricated in the latest release.
The best way to replace this is to make your own Module that imports (and exports) only the modules that are actually used in your application.
I managed to fix this issue by creating this class:
import { NgModule } from '#angular/core';
import { CommonModule } from '#angular/common';
import { MdMenuModule, MdIconModule, MdRippleModule, MdToolbarModule, MdSidenavModule, MdButtonModule } from '#angular/material'
// Add animations
import { BrowserAnimationsModule } from '#angular/platform-browser/animations'
const MATERIAL_MODULES = [
MdMenuModule,
MdIconModule,
MdRippleModule,
MdToolbarModule,
MdSidenavModule,
MdButtonModule,
BrowserAnimationsModule
];
#NgModule({
imports: MATERIAL_MODULES,
exports: MATERIAL_MODULES
})
export class AngularMaterialModule { }
This module should be included in your own app.module
Good luck!

ionic2 CloudModule.forRoot() error angular.element is not function

i try to setup ionic Cloud in my app, but i have this error : Uncaught TypeError: angular.element is not a function(…) for this line :
CloudModule.forRoot(cloudSettings)
my code : for app.module.ts
import { NgModule, ErrorHandler } from '#angular/core';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { CloudSettings, CloudModule } from '#ionic/cloud-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import {DetailsPage} from '../pages/details/details';
import {OtherPage} from '../pages/other-page/other-page';
import { Page1 } from '../pages/page1/page1';
import { Page2 } from '../pages/page2/page2';
var cloudSettings: CloudSettings = {
'core': {
'app_id': 'xxxxx'
}
};
console.log(cloudSettings);
#NgModule({
declarations: [
MyApp,
HomePage
],
imports: [
IonicModule.forRoot(MyApp),
CloudModule.forRoot(cloudSettings)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage
],
providers: [{provide: ErrorHandler , useClass:IonicErrorHandler}]
})
export class AppModule {}
thank's you,

Unit testing component with angulartics2 - Can't bind to 'angularticsCategory' since it isn't a known property of 'div'

I am starting a project using Angular 2.0.0 stable release created with angular-cli 1.0.0-beta.14 and angulartics 1.1.9.
I am trying to start some simple unit testing and am recording clicks on a button component
<div class="sidebar-toggle" (click)="toggleSideBar()" angulartics2On="click" angularticsCategory="{{ expanded ? 'expand': 'collapse' }}">
//divContent
</div>
However, when I run the test which is simple bootstrapping the component I get the error
Can't bind to 'angularticsCategory' since it isn't a known property of 'div'
The app works fine but the issue only comes up in testing. I can't find an example where someone is having the same error in testing. I know I am missing something like not properly exposing the angulartics2 lib in my karma.conf OR not injecting the Angulartics or a mocked dependency in my Testbed config.
Really lost and would like to know if anyone is having similar problems. Can provide more code snippets if needed but don't want to dump the whole file nobody's got time to read that!
In my case to get Angulatics2 unit tests to work I had to:
1) Import Angulartics2Module into the root app.module.ts
import { Angulartics2Module } from 'angulartics2';
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { environment } from '../environments/environment';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
#NgModule({
declarations: [
AppComponent,
HeaderComponent,
],
imports: [
BrowserModule,
Angulartics2Module.forRoot({ developerMode: !environment.production }),
AppRoutingModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
2) Enable tracking in app.component.ts
import { Angulartics2GoogleGlobalSiteTag } from 'angulartics2/gst';
import { Component } from '#angular/core';
import { RouterOutlet } from '#angular/router';
#Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
constructor(
public angulartics2GoogleGlobalSiteTag: Angulartics2GoogleGlobalSiteTag,
) {
this.angulartics2GoogleGlobalSiteTag.startTracking();
}
}
3) Import Angulartics2Module.forRoot() and Angulartics2 provider in to app.component.spec.ts
import { HttpClientTestingModule } from '#angular/common/http/testing';
import { TestBed, async } from '#angular/core/testing';
import { RouterTestingModule } from '#angular/router/testing';
import { Angulartics2, Angulartics2Module } from 'angulartics2';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule,
Angulartics2Module.forRoot(),
HttpClientTestingModule,
],
declarations: [
AppComponent,
HeaderComponent,
],
providers: [
Angulartics2,
],
}).compileComponents();
}));
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});
});
and for any other component.spec.ts files that you have using the Angulatics2 directives.