nativescript-ng2-magic looks for html in wrong path - nativescript

I have a problem with nativescript-ng2-magic. I have a web app, and now I am trying to build a mobile app by using nativescript-ng2-magic for sharing code.
In my starting component (app.component.*) (path: app/app/) I have included page-router-outlet to be redirected to the login page. For this, I have declared the path in app.routing.ts
{path: "", redirectTo: "/login"}.
The files for the login page are under app/components/login. in login.routing I declared the path
{ path: "login", component: LoginComponent }. Then I am doing a RouterModule.forChild(loginRoutes);
The login component (same path as the login.routing.ts) looks like this:
#Component({
selector: "login",
templateUrl: "./login.component.html",
styleUrls: ["./login.common.css"],
})
export class LoginComponent implements OnInit {
...
}
When I want to start the mobile app I got the error message:
Error: File /data/data/org.nativescript.nativescript/files/app/app/login.component.tns.html does not exist.
That's right. As I wrote above the file is under app/app/components/login. Why is nativscript-ng2-magic looking in the wrong path?

Perhaps you should set the full path to the login.component.htmland login.common.css. For example
#Component({
selector: "login",
templateUrl: "components/loginlogin.component.html",
styleUrls: ["components/loginlogin.common.css"],
})
export class LoginComponent implements OnInit {
...
}

Related

MSTeams Config page Angular 12 SPA with routing

I'm using Angular 12 and am writing a simple group tab app. I'm working on the config page component and the html looks like this:
<br />
<br />
<br />
<p>Configuration 3</p>
<input type="text" placeholder="Some Test" />
In a normal browser, the text and box appears. But if I try to do the same thing via the install to tab path, I don't get the text or input box at all.
I think this might have something to do with routing but can't confirm.
The app-routing-module is pretty simple:
const routes: Routes = [
{
path: '',
component: HomeComponent,
},
{
path: 'configuration',
component: ConfigurationComponent,
},
];
#NgModule({
imports: [
RouterModule.forRoot(routes, {
initialNavigation:
!BrowserUtils.isInIframe() && !BrowserUtils.isInPopup()
? 'enabled'
: 'disabled',
}),
],
exports: [RouterModule],
})
export class AppRoutingModule {}
So what does it take to get the SPA to route to the configuration page when used within teams?
Configuration Component: (URL purposed changed to protect the innocent)
import { Component, OnInit } from '#angular/core';
import { Inject, AfterViewInit, ElementRef } from '#angular/core';
import { DOCUMENT } from '#angular/common';
import * as microsoftTeams from '#microsoft/teams-js';
#Component({
selector: 'app-configuration',
templateUrl: './configuration.component.html',
styleUrls: ['./configuration.component.scss'],
})
export class ConfigurationComponent implements OnInit, AfterViewInit {
constructor(
#Inject(DOCUMENT) private document: Document,
private elementRef: ElementRef
) {}
ngOnInit(): void {
microsoftTeams.initialize();
}
ngAfterViewInit() {
console.log('Initializing ms teams');
microsoftTeams.settings.registerOnSaveHandler((saveEvent) => {
microsoftTeams.settings.setSettings({
entityId: '',
contentUrl: 'https://test.ngrok.io',
suggestedDisplayName: 'Test',
websiteUrl: 'https://test.ngrok.io',
});
saveEvent.notifySuccess();
});
console.log('Register on save');
microsoftTeams.settings.setValidityState(true);
}
}
Thanks,
Nick
In order to render a tab in Teams. You need to make sure that it is iFramable. Please see the document- Tab requirements.
Make sure that you have given the domain in valid domains in your manifest.
Please share more details like console error, what are you using static tab or config and manifest, if issue isn't solve for you
I traced my problem for this particular question to the line:
initialNavigation:
!BrowserUtils.isInIframe() && !BrowserUtils.isInPopup()
? 'enabled'
: 'disabled',
This example is in a lot of the code for SPAs in and Teams Tabs.
I just have it set to 'enabled' for now and I can get beyond the purpose of this question.

Is there a specific way of using nativescript-videorecorder plugin to work with angular?

I am unable to get the nativescript-videorecorder to work in my app.
I had installed the plugin and used the code given on the github https://github.com/triniwiz/nativescript-videorecorder for typescript. I created a simple HTML ui and tried to call a function to open the camera to record video. However it is does not work
For app.component.html i used the tag <Image src="videoCam" (tap)="onCam()">
For app.component.ts i used the below code
import { VideoRecorder, Options as VideoRecorderOptions } from 'nativescript-videorecorder';
#Component({
moduleId: module.id,
selector: "ns-app",
templateUrl: "app.component.html"
})
export class AppComponent {
export class AppComponent {
onCam() {
const options: VideoRecorderOptions = {
hd: true
saveToGallery: true
};
const videorecorder = new VideoRecorder(options);
videorecorder.record().then((data) => {
console.log(data.file)
}).catch((err) => {
console.log(err)
});
}
}
Is there anything i am missing to get this to work ?

handling link opening event in HtmlView

I have a html code that has a link inside it. code below is my template:
<HtmlView [html]="htmlString" ></HtmlView>
this is my component:
import { Component } from "#angular/core";
#Component({
moduleId: module.id,
templateUrl: "./creating-htmlview.component.html"
})
export class CreatingHtmlViewExampleComponent {
public htmlString: string;
constructor() {
this.htmlString = 'google';
}
}
how to handle a element inside of HtmlView when it run ? there is a way to detect when user run the link?
That's not supported yet, there is an open feature request. You may write a plugin that implements native apis like ClickableSpan or Linkify.

ngOnInit doesn't run until after I navigate to another component

In my NativeScript app, I have the route set up as
export const routes = [
{ path: "", component: AppComponent},
{ path: "home", component: HomeComponent},
{ path: "login", component: LoginComponent},
{ path: "news" , component: NewsComponent}
];
After a user is logged in through firebase the user is auto redirected to the HomeComponent. I should mention that I have a user service that gets fired from the AppComponent Constuctor that determines if a user is already logged in then redirects them to login or home.
I have console.log() spread across the component to see when things gets triggered so I can try to figure out where to place the code.
import {Component, OnInit} from "#angular/core";
import {Page} from "ui/page";
import {RouterExtensions} from 'nativescript-angular/router';
import firebase = require("nativescript-plugin-firebase");
#Component ({
selector : "home",
templateUrl: "./pages/home/home.html",
styleUrls: ["./pages/home/home.css"]
})
export class HomeComponent implements OnInit {
private router;
constructor(page: Page, router: RouterExtensions) {
console.log("HOME CONSTRUCTOR TRIGGERED");
page.actionBarHidden = false;
this.router = router;
}
ngOnInit(){
console.log("HOME NGONIT TRIGGERED");
}
goToNews(){
this.router.navigate(["/news"]);
}
}
In home.html I have a button that triggers goToNews(). When I load up the app, I can see in my console when HomeComponent constructor gets triggered, but I never see ngOnInit get triggered. The strange thing is that when I click on the button to navigate to /news, this is when I see the HomeComponent ngOnInit fire in my console. Is this the way it's suppose to work?
This all comes down to a "big picture understanding" where I'm trying to figure out the best place to put my logic down when HomeComponent gets loaded. I read that putting it in the constructor was a bad idea and having it in ngOnInit is ideal however I don't see how this can make any sense if ngOnInit only gets triggered after I try to navigate away from the component.
Please help me understand this.
UPDATE: I added a console.log to ngOnInit in AppComponent and this does get fired when the app first loads. So it must be the navigation in the services that is causing ngOnInit to not fire in HomeComponent.
Try putting the router.navigate() into a separate "Zone":
import:
import { NgZone } from "#angular/core";
inject:
constructor(private zone: NgZone) { ... }
apply:
this.zone.run(() => {
this.router.navigate(["/news"]);
});
found here.

Spec Has No Expectations error on Angular 2 templateUrl

I have a angular 2 Component MyComp
#Component({
selector: 'myform',
templateUrl: './myform.html',
providers: [HTTP_PROVIDERS],
directives: [ROUTER_DIRECTIVES]
})
This is my spec.
it('should work', injectAsync([TestComponentBuilder], (tcb) => {
return tcb.createAsync(MyComp).then((fixture) => {
fixture.detectChanges();
expect(1+ 1).toEqual(2);
});
}));
When i execute the tests its giving me an error
Can't bind to 'ngForOf' since it isn't a known native property
The actual code works, but its only the tests that are failing,
Update :
Spec works if i replace templateUrl with template.
i.e if i just try with
template: <h1>Fake</h1> <ul> <li *ngFor="#item of items"> </li> </ul>
Interested to know if anyone has tested components with templateUrl with angular 2.0 beta version.
Thanks !
You should add ngFor or CORE_DIRECTIVES to the component directives:
import { CORE_DIRECTIVES } from 'angular2/common';
#Component({
selector: 'myform',
templateUrl: './myform.html',
providers: [HTTP_PROVIDERS],
directives: [ROUTER_DIRECTIVES, CORE_DIRECTIVES] // <- HERE!!!
})
export class MyForm { /* ... */ }
or
import { NgFor } from 'angular2/common';
#Component({
selector: 'myform',
templateUrl: './myform.html',
providers: [HTTP_PROVIDERS],
directives: [ROUTER_DIRECTIVES, NgFor] // <- HERE!!!
})

Resources