I'm playing around with Angular2, using typescript and there is something that is not rendering as I hoped for, I don't know what I'm doing wrong.
This code is working
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: `
<svg viewBox="0 0 900 500" preserveAspectRatio="xMidYMid meet">
<svg:circle cx=50 cy=50 r=10 />
<svg:circle cx=71 cy=71 r=20 />
<svg:circle cx=106 cy=106 r=30 />
</svg>
`
})
export class AppComponent {
}
But when I'm trying to bind it on an object with *ngFor, it's not rendering...
@Component({
selector: 'my-app',
template: `
<svg viewBox="0 0 900 500" preserveAspectRatio="xMidYMid meet">
<svg:circle *ngFor="#circle of circles"
[attr.cx]="circle.x"
[attr.cy]="circle.y"
[attr.r]="circle.radius" />
</svg>
`
})
export class AppComponent {
circles = [
{x: 50, y: 50, radius: 10},
{x: 75, y: 75, radius: 20},
{x: 115, y: 115, radius: 30}
];
}
I'm trying to follow this tutorial (http://teropa.info/blog/2016/02/28/metabubbles-generative-art-with-angular-2.html#drawing-svg-circles) using typescript instead ...
Seems to be a duplicate of AngularJS 2 and SVG <ellipse> elements not rendered
Dom elements not generated for every iteration and properties(attributes) not generated...
THIS IS NOW FIXED It works in Chrome, but not in IE 11. IE Console was not displaying the javascript errors and chrome console was. That how I managed to fix my issue trying to solve the javascript errors I had.
I turned out to change the SystemJS config. Instead of using the following config as stated there https://angular.io/docs/ts/latest/quickstart.html#!#tsconfig
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
I used it :
System.config({
transpiler: 'typescript',
typescriptOptions: {
emitDecoratorMetadata: true
},
map: {
app: "./app"
},
packages: {
app: {
main: './main',
defaultExtension: 'js'
}
}
});
That's one part I'm not understanding very well, are those typescriptoptions are overrideing tsconfig.json file? I don't know yet... I don't know yet what is this mapping for and what are the packages, but at least I can go on with my learning
you can try this.
defining your circle component
circle.component.hmtl :
and your root html will be like
similarly you can use all the other svg shapes by creating similar components with selector as defied above.
You can use this library which provides all the svg elements
https://www.npmjs.com/package/angular-svg
I'm new to angular2 but this works for me, maybe you have to add:
directives:[NgFor]
import { NgFor } from 'angular2/common';
sorry for my English hope it will help you.
Update:
I have also tried without
directives:[NgFor]
import { NgFor } from 'angular2/common';
and it works.
package.json info