I have sharepoint add-in project, I have inculuded necessary angular2 packages and ts files as you see ss of solution explorer in below:
and here is my ts file contents;
boot.ts
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
bootstrap(AppComponent)
app.component.ts
import {Welcome} from './app.module';
import {Component} from 'angular2/core';
#Component({
selector: 'app-main',
template:'<h1>${Welcome.getMessage()}</h1>'
})
export class AppComponent {}
app.module.ts
export class Welcome {
static getMessage() {
return "Hello World!";
}
}
when I run this application I always get this error message in output window:
> #"Error 1
> CorrelationId: ae2bcaba-cdac-4178-bd39-2aca278a2e31
> ErrorDetail: There was a problem with activating the app web definition.
> ErrorType: App
> ErrorTypeName: App Related
> ExceptionMessage: Failed to instantiate file "app.module.ts" from module "RootModule": Source path
> "Features\SharePointAddIn4_Feature1\app.module.ts" not found.
> Source: AppWeb
> SourceName: App Web Deployment
I have search but cant find any solution helped me.. any idea how to fix this?
To resolve this, I had to set the tsconfig.json file (and others) to not deploy, and remove it from Elements.xml in the root of the project.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="RootModule">
</Module>
</Elements>
Hey Buddy there are few points to be clear here before answer
you are using too old version of angular2 may be you are in angular2 beta
(as you are using 'angular2/core' now it is '#angular/*')
you are using wrong syntax according to me
{Welcome.getMessage()}
there are syntax like this
{{Welcome.getMessage()}}
also you are trying to access class Welcome without even initializing in the constructor of app.component.ts file, which is wrong .
Related
I just discovered this framework and I was loving it so far. But then I tried to create a feature module and for some reason it's not working.
I created a new Aurelia app using the CLI:
au new
Then I started coding, created an HTML-only custom element and used it, it worked great.
The problem came when I wanted to create a feature module.
First, this is my src folder (yeah, I'm going with a classic todo-list app):
So, in the main.js file I've declared the todo feature module:
import 'regenerator-runtime/runtime';
import * as environment from '../config/environment.json';
import {PLATFORM} from 'aurelia-pal';
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.feature(PLATFORM.moduleName('todo/index'));
aurelia.use.developmentLogging(environment.debug ? 'debug' : 'warn');
if (environment.testing) {
aurelia.use.plugin(PLATFORM.moduleName('aurelia-testing'));
}
aurelia.start().then(() => aurelia.setRoot(PLATFORM.moduleName('app')));
}
Now, depending on what I do I get one error or another.
Option 1
If I configure todo/index.js as a module like this:
export function configure(config) {
config.globalResources(['./todo-list', './todo-item']);
}
Then I get this warning and the web goes blank:
Option 2
If I comment out the config.globalResources() line in todo/index.js then I don't get the warning, the page seems to work. But when I click on the button to add a new Todo item I get an error that the function doesn't exist.
In app.html I import todo/todo-list.html:
<template>
<require from="./app-header.html"></require>
<require from="./todo/todo-list.html"></require>
<app-header></app-header>
<main>
<todo-list></todo-list>
</main>
</template>
And this is the content of todo-list.html:
<template>
<form>
<label for="item-text">Añadir elemento: </label>
<input id="item-text" value.bind="newTodo"/>
<button type="button" click.trigger="addTodo()">Añadir</button>
</form>
</template>
This is todo-list.js:
import {TodoItem} from './todo-item';
export class TodoList {
constructor() {
this.todos = [];
this.newTodo = '';
this.lastId = 0;
}
addTodo() {
this.lastId++;
this.todos.push(new TodoItem(this.lastId, this.newTodo));
this.newTodo = '';
console.log(this.todos.length);
}
}
So, I guess if I don't configure todo/index.js as a module Aurelia doesn't know that todo-list.html and todo-list.js are related and that's why it can't find the function addTodo().
What am I doing wrong?
I have created a github repo with the code: https://github.com/dhAlcojor/aurelia-todo-list
You need to wrap all references to module names (files) in PLATFORM.moduleName calls.
So instead of
export function configure(config) {
config.globalResources(['./todo-list', './todo-item']);
}
switch to
export function configure(config) {
config.globalResources(
PLATFORM.moduleName('./todo-list'),
PLATFORM.moduleName('./todo-item');
}
Also note that I got rid of wrapping the paths in an array. The framework does that for you.
I'm using Vue CLI 3 version 3.0.5.
In project configuration, I use Nightwatch as e2e test tool.
I try to use page objects, so I had nightwatch.config.js file in project root, and add page_objects_path inside like below:
{
page_objects_path : "/tests/e2e/page-objects"
}
Then I create page-objects folder as this path: /tests/e2e/page-objects.
Then I setup a page object Entry.js under that folder and try to use it in test:
/tests/e2e/page-objects/Entry.js
vmodule.exports = {
'Test Page Object': browser => {
browser
.url(process.env.VUE_DEV_SERVER_URL)
.waitForElementVisible('#app', 5000)
browser.page.Entry().sayHello()
browser.end()
}
}
And the error message shows:
Cannot read property 'Entry' of undefined .
It looks like my page object setup is not correct...
Could anyone help providing a correct implementation of NightWatch page object in Vue CLI v3.0.5 ? Thanks...
Ah, I know why it won't work.
Because nightwatch.config.js is a javascript file, I should export it first, then the plugin can read it.
module.export = {
page_objects_path : "/tests/e2e/page-objects"
}
Sorry for the dumb question.
I'm facing an issue when I try to bundle Aurelia-hammer with the CLI.
The app still keeps pulling hammer-swipe.js, hammer-tap.js,... from the node_modules folder.
When I inspect the plugin's AMD structure, these are defined as global resources:
function configure(frameworkConfig) {
frameworkConfig.globalResources('./hammer-swipe');
frameworkConfig.globalResources('./hammer-tap');
frameworkConfig.globalResources('./hammer-press');
frameworkConfig.globalResources('./hammer-hold');}
Is there any way to bundle these with the CLI? I tried adding these files to the "resources" element in aurelia.json without success.
the plugin author should export those classes: (HammerPressCustomAttribute...) so they could be traced properly. But you can dummy-import theme yourself as a workaround:
import { HammerPressCustomAttribute } from 'aurelia-hammer/hammer-press';
import { HammerSwipeCustomAttribute } from 'aurelia-hammer/hammer-swipe';
import { HammerTapeCustomAttribute } from 'aurelia-hammer/hammer-tap';
normally you have to do this as well:
import { HammerHoldCustomAttribute } from 'aurelia-hammer/hammer-hold';
but the class exported from hammer-hold.js is named HammerPressCustomAttribute (oops looks like copy-paste issue) so just reference the file even with a non existent class.
import { HammerHoldCustomAttribute } from 'aurelia-hammer/hammer-hold';
this should fix your problem (I hope). It's best to open an issue in the plugin repo and ask the author to export those classes (and rename the duplicate one).
I have got the type definition file for a library - seneca. I don't know know how to import this module into typescript source.
I have used
/// <reference path="../custom_typings/seneca.d.ts" />
Please see the below seneca.d.ts file
I want to use the add(..) function in the seneca module.
Just add it to the module s e.g.
module s {
export var add:Function; // Sample
I've initialised aurelia with
<body aurelia-app>
...
</body>
The getting started guide (http://aurelia.io/get-started.html) says that this will, by default, try to load up app.js and app.html
How can I tell aurelia to load up main.js and main.html?
if I do <body aurelia-app="main"> only main.js is accessed and the view isn't shown.
When you supply a value for the aurelia-app attribute, Aurelia will load that module and call the configure method that is exported by this module. This is explained in the documentation.
Your configuration must tell Aurelia which module to load for the app root. Here is the example from the documentation:
import {LogManager} from 'aurelia-framework';
import {ConsoleAppender} from 'aurelia-logging-console';
LogManager.addAppender(new ConsoleAppender());
LogManager.setLevel(LogManager.logLevel.debug);
export function configure(aurelia) {
aurelia.use
.defaultBindingLanguage()
.defaultResources()
.history()
.router()
.eventAggregator()
.plugin('./path/to/plugin');
aurelia.start().then(a => a.setRoot('app', document.body));
}
What you're expecting to happen isn't the actual behavior. Setting the value of attribute points Aurelia to a configuration module that will point aurelia to the app root. In your case, you might want to do something like this:
index.html
...
<body aurelia-app="configuration">
...
src\configuration.js
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging();
aurelia.start().then(a => a.setRoot('main', document.body));
}
And then src\main.js and src\main.html will be loaded as you expect (well, actually it will be dist\main.js and dist\main.html, but the files you're editing are in the src directory).