Skip to content

Instantly share code, notes, and snippets.

View teomanofficial's full-sized avatar

Hasan Teoman Tıngır teomanofficial

View GitHub Profile
@teomanofficial
teomanofficial / chat-room.component.ts
Created January 31, 2024 23:58
Angular Writable Signals
export class ChatRoomComponent implements OnInit {
onlineUsersCount: WritableSignal<number> = signal(0)
ngOnInit() {
// Update count via setter
app.events.on('chat.room.connected', () => {
this.onlineUsersCount.set(this.onlineUsersCount() + 1);
});
// Update count via callback
@teomanofficial
teomanofficial / after-render-hook.component.ts
Created November 27, 2023 22:35
Angular AfterRender Hook
@Component({
selector: 'my-cmp',
template: `
<span #content>{{ ... }}</span>
<span #tooltip>{{ ... }}</span>
`,
})
export class MyComponent {
@ViewChild('content') contentRef: ElementRef;
@ViewChild('tooltip') tooltipRef: ElementRef;
@teomanofficial
teomanofficial / angular-defferable-views.html
Created November 27, 2023 20:28
angular deferrable views
@defer (on viewport) {
<comment-list>
@for(comment of comments) {
<comment-item [comment]="comment"></comment-item>
}
<comment-list />
} @placeholder {
<img src="skelton-comments.png">
}
@teomanofficial
teomanofficial / angular-new-control-flow-loops.html
Created November 27, 2023 20:14
Angular New Control Flow Loops
@for (user of users; track user.id) {
{{ user.name }}
} @empty {
Empty list of users
}
@teomanofficial
teomanofficial / angular-new-control-flow-switch.html
Created November 27, 2023 20:12
Angular New Control Flow Switch
@switch (accessLevel) {
@case ('admin') { <admin-dashboard/> }
@case ('moderator') { <moderator-dashboard/> }
@default { <user-dashboard/> }
}
@teomanofficial
teomanofficial / angular-new-control-flow.html
Created November 27, 2023 20:08
Angular New Control Flow Elements If Else
@if (loggedIn) {
The user is logged in
} @else {
The user is not logged in
}
@teomanofficial
teomanofficial / if-else-directive.html
Created November 27, 2023 20:07
Angular If Else Directive
<div *ngIf="loggedIn; else anonymousUser">
The user is logged in
</div>
<ng-template #anonymousUser>
The user is not logged in
</ng-template>
@teomanofficial
teomanofficial / openlayers.ts
Created November 24, 2023 22:11
OpenLayers Nasıl Kullanılır ?
fetch('/data.kml')
.then(res => res.text())
.then(geojson => {
const reader = new KML({ showPointNames: false });
const features = reader.readFeatures(geojson, { featureProjection: 'EPSG:3857' });
const vectorSource = new VectorSource({ features });
map.addLayer(new VectorLayer({ source: vectorSource as any }))
})
.catch(() => {
alert('hata Oluştu!');
@teomanofficial
teomanofficial / openlayers.ts
Created November 24, 2023 21:29
OpenLayers Nasıl Kullanılır ?
fetch('/data.json')
.then(res => res.json())
.then(geojson => {
const reader = new GeoJSON({ featureProjection: 'EPSG:3857' });
const features = reader.readFeatures(geojson);
const vectorSource = new VectorSource({ features });
map.addLayer(new VectorLayer({ source: vectorSource }))
})
.catch((e) => {
alert('hata Oluştu!');
@teomanofficial
teomanofficial / openlayers.ts
Created November 24, 2023 21:07
Openlayers Nasıl Kullanılır ?
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import XYZ from 'ol/source/XYZ';
const map = new Map({
target: 'map',
layers: [
new TileLayer({
source: new XYZ({