
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
angular-kladr
Advanced tools
Angular 4+ package for better experience using kladr api service
$ npm install angular-kladr --save
import { KladrModule } from 'angular-kladr';
Add imported module to the imports section in NgModule decorator
@NgModule({
.
.
.
imports: [
:
KladrModule;
]
})
import { Component } from '@angular/core';
import { KladrService } from 'angular-kladr';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(
private kladr$: KladrService
){ }
}
Basically, you need to create collection of type Observable<BaseResponse> imported from the package.
public cities: Observable<BaseResponse>;
Then create FormControl, which you will get value from in order to pass it into kladr api request.
Assign the request to the collection in the contructor as shown below:
constructor(private kladr$: KladrService) {
this.cityControl = new FormControl('');
this.cities = this.cityControl.valueChanges
.pipe(
takeUntil(this.ngUnsubscribe),
debounceTime(100),
switchMap(value => {
const context: SearchContext = {
...this.regionContext,
query: value
};
return this.kladr$.api(context);
})
);
}
private ngUnsubscribe = new Subject<void>();
private regionContext: SearchContext = {
limit: 10,
contentType: ContentType.region
};
public cities: Observable<BaseResponse>;
public cityControl: FormControl;
Also, we need to know which city a client will choose to provide some kind of autocomplete
public shosenCity: BaseModel;
chooseCity(city: BaseModel) {
this.shosenCity = city;
this.cityControl.setValue(city.name);
}
To make this work let's add some html code in our template:
<div>
<label for="city">Choose city</label>
<input type="text" id="city" name="city" [formControl]="cityControl">
<ul>
<li *ngFor="let city of (cities | async)?.result">
<a href="javascript:void(0)" (click)="chooseCity(city)">{{city.name}}</a>
</li>
</ul>
<div>
<pre>{{chosenCity | json}}</pre>
</div>
</div>
Combining all together:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { KladrModule } from 'angular-kladr';
import { ReactiveFormsModule } from '@angular/forms';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
KladrModule,
ReactiveFormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
import { Component } from '@angular/core';
import { KladrService, BaseResponse, SearchContext, ContentType, BaseModel } from 'angular-kladr';
import { Observable, Subject } from 'rxjs';
import { takeUntil, debounceTime, switchMap } from 'rxjs/operators';
import { FormControl } from '@angular/forms';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(private kladr$: KladrService) {
this.cityControl = new FormControl('');
this.cities = this.cityControl.valueChanges
.pipe(
takeUntil(this.ngUnsubscribe),
debounceTime(100),
switchMap(value => {
const context: SearchContext = {
...this.regionContext,
query: value
};
return this.kladr$.api(context);
})
);
}
private ngUnsubscribe = new Subject<void>();
private regionContext: SearchContext = {
limit: 10,
contentType: ContentType.region
};
public cities: Observable<BaseResponse>;
public cityControl: FormControl;
public chosenCity: BaseModel;
chooseCity(city: BaseModel) {
this.chosenCity = city;
this.cityControl.setValue(city.name);
}
}
<div>
<label for="city">Choose city</label>
<input type="text" id="city" name="city" [formControl]="cityControl">
<ul>
<li *ngFor="let city of (cities | async)?.result">
<a href="javascript:void(0)" (click)="chooseCity(city)">{{city.name}}</a>
</li>
</ul>
<div>
<pre>{{chosenCity | json}}</pre>
</div>
</div>
The demo will be available soon.
FAQs
Angular 4+ package for better experience using kladr api service
The npm package angular-kladr receives a total of 4 weekly downloads. As such, angular-kladr popularity was classified as not popular.
We found that angular-kladr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.