I've previously used the following code
import { clone } from '../../utilities/javascript';
and in the javaccript.ts
export function clone(source: any) {...}
In my module i made the call using the following syntax:
this.x=clone(y);
And all was working.
However, since I am using Angular-cli, the following exception comes up in Chrome:
error_handler.js:47 EXCEPTION: Cannot read property 'clone' of undefined
Is there something in my syntax that is wrong, which surfaced just as I switched to Angular-cli?
I currently copy this function into every module in which i use it, which solves the problem, but that is not something I am comfortable with.
try to import it in the following way:
import * as javascriptUtils from '../../utilities/javascript';
then call it with:
this.x=javascriptUtils.clone(y);
taken from https://github.com/angular/angular-cli#3rd-party-library-installation
Related
Lets say I've got the following json file (root of angular application):
{
"propertyName": "ABC"
}
I know that TypeScript cannot handle JSON imports directly so I delcared the following module according to TypeScript module documentation using wildcard (typings.d.ts):
declare module "*.json" {
const value: any;
export default value;
}
Now I am able to import a local json file (structure above) like this:
import * as config from './config.json';
After that I am able to use any property of the import like this:
let propertyA: string = (<any>config).propertyName;
Everything is fine, but when I try to use
let propertyA: string = config.propertyName;
I get the following error message:
ERROR in src/main.ts(9,26): error TS2339: Property 'propertyName'
does not exist on type 'typeof "*.json"'.
Any suggestions how to avoid this error during build process? The process finished successfully (including this error message) and I'm able to use the web application and also the needed property. It just generates an error message
I've had a similiar problem, since it's a json file, doesn't have a module and doesn't need to be compiled you can import it like it would be in javascript.
const config = require('./config.json');
There won't be any any error accessing the config attributes then and it still be working fine.
Remember you may need to import the #types/node package in order to use the require method.
I had a groovy code wich contains "import groovy.json.JsonSlurper".
I have spent a day testing and i dont know how to load external libraries using declarative syntax.
This is my code:
pipeline {
agent any
import groovy.json.JsonSlurper
stages {
stage("test") {
steps {
}
}
}
}
I have read the jenkins documentation, and i have tried to use the next but without success:
#Grab('groovy.json.JsonSlurper')
import groovy.json.JsonSlurper
both import and #Grab is not recognized. Some idea?
Thanks!
What #Daniel Majano says is true about the import syntax, but the #Grab syntax I found holds differences of behavior between a Pipeline script maintained directly in Jenkins vs Pipeline script from SCM.
When I placed a Grab command in the Pipeline script for a tester pipeline job I found that it didn't make any difference whether the Grab command was there or if it was commented out.
However when used from a Pipeline script from SCM it would throw the following exception...
java.lang.RuntimeException: No suitable ClassLoader found for grab
I removed it from the SCM script and everything worked out in the end.
Additional Background
I'm not sure why the grab was choking in the SCM version, but there's definitely some working parts to the groovy editor because if you define a partial grab command it will give you some validation errors pointing to the broken line as you see in the red X box below, with the error The missing attribute "module" is required in #Grab annotations:
Therefore the script validator is aware of the Grab annotation as it calls it and that it has both a group and module attribute. I'm using the so called shorthand notation in this example.
I have an application in Angular 4 and I want to display version of my application somewhere in the view. The version string is expectedly contained in package.json version property.
What I've tried is to create a class and import JSON file directly into it, then expose the variable through getter method:
import * as PACKAGE from './../../../package.json';
export class PackageService {
public static getVersion (): string {
return (PACKAGE as any).version;
}
}
However, this solution raises compilation problems such as this one:
ERROR in Error encountered resolving symbol values statically. Expression form not supported (position 8:13 in the original .ts file), resolving symbol PackageService.getVersion in ./src/app/services/package.service.ts, resolving symbol AppModule in ./src/app/app.module.ts, resolving symbol AppModule in ./src/app/app.module.ts
webpack: Failed to compile.
Looks like the problem is with method being static. When I convert this class to normal Angular injectable service. It compiles correctly.
I'm using static method in order to add version string to DI container with: {provide: DI_VERSION, useValue: PackageService.getVersion()}, where DI_VERSION is an injection token. This would allow me to access the version string directly without injecting entire service and calling methods on it.
What exactly is causing this error and how do I fix it?
I'm working on a project using actionscript and Flex. For some reason I have a problem importing the com.adobe.serialization.json.JSON class.
When I'm working only with the FlexSDK files and try to use it I'm getting
the following error:
Error:(142, 70) [..]: Error code: 1120: Access of undefined property
JSON.
And of course IntelliJ marks this file and the import in red.
On the other hand when I import the corelib.swc that includes this file I get the following error:
Error:[..]: Can not resolve a multiname reference unambiguously. JSON
(from /Volumes/backup/FlexSDK/frameworks/libs/air/airglobal.swc(JSON,
Walker)) and com.adobe.serialization.json:JSON (from
/Volumes/backup/.../libs/corelib.swc(com.adobe.serialization.json:JSON))
are available.
What is going on here? How can I solve this?
JSON is a top level class available in all the scopes since FP11. Trying to import any class with name JSON will result in an error. If (for some reason) you really do not want to use the already available JSON class and instead import a custom one you'll have to rename it.
Using Intellij, the best you can do is use the JSON class from the current SDK that you have, it has the methods parse() and stringify(). those two methods do the same as the corelib methods for the json.
In case you wanted to use the com.adobe.serialization.json.JSON it will enter in conflict with the one declared in the SDK.
Hope the information is useful
I know very little about Flash, but I need to be able to call a JS function from inside a ActionScript file.
When I enter the line:
ExternalInterface.call("alert", "test");
I get the error:
There is no method with the name 'ExternalInterface'.
In the tutorials it seems I have to include the namespace:
import flash.external.ExternalInterface;
but I don't know where to put that?
I place it outside the class that extends a mediaclip and it does nothing.
How do I include that reference so that the ExternalInterface method is recognized?
What's odd is that intellisense works and allows me to type it in and gives me the overloaded methods, so it knows what I'm trying to say, it just doesn't work when I try to compile it.
You could also try access the class doing this:
flash.external.ExternalInterface.call("alert", "test");
That way you don't have to import the package with the class.