Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DefaultValueAccessor directive Standalone #49720

Closed
ghost opened this issue Apr 5, 2023 · 3 comments
Closed

Make DefaultValueAccessor directive Standalone #49720

ghost opened this issue Apr 5, 2023 · 3 comments
Labels
area: forms cross-cutting: standalone Issues related to the NgModule-less world
Milestone

Comments

@ghost
Copy link

ghost commented Apr 5, 2023

Which @angular/* package(s) are relevant/related to the feature request?

forms

Description

When we want to make a simple custom value accessor, according to the docs, we can use DefualtValueAccessor.

the example:

Let's suppose we have app-my-custom-control component

@Component({
  selector: 'app-my-custom-control',
  templateUrl: './my-custom-control.component.html',
  styleUrls: ['./my-custom-control.component.scss'],
})
export class MyCustomControlComponent implements OnInit {
  constructor(private ngControl: NgControl) {}
  ngOnInit(): void {
   //testing code
    this.ngControl.valueChanges?.subscribe((data) => {
      console.log(data);
    });
  }
} 

We can use app-my-custom-control as Value Accessor One if we add ngDefaultControl directive.

@Component({
  selector: 'app-default-custom-control',
  styleUrls: ['./default-custom-control.component.scss'],
  template: `
    <app-my-custom-control
      [(ngModel)]="value"
      ngDefaultControl
    ></app-my-custom-control>
  `,
})
export class DefaultCustomControlComponent implements OnInit {
  value = '2';

  ngOnInit(): void {
    setInterval(() => {
      this.value = new Date().toString();
    }, 3000);
  }
}

Which works fine. But we have to add ngDefaultControl in all the places we use it.

to avoid duplication, we can add DefaultValueAccessor directive in hostDirectives property like this:


@Component({
  selector: 'app-my-custom-control',
  templateUrl: './my-custom-control.component.html',
  styleUrls: ['./my-custom-control.component.scss'],
  hostDirectives: [DefaultValueAccessor],
})

Unfortunately, we can't do this because DefaultValueAccessor is not standalone,

So the proposal is to make it standalone.

Proposed solution

The proposed solution is to make DefaultValueAccessor directive standalone to be able to put it in hostDirective property

Alternatives considered

I don't see any alternative besides that use it as it is right now

@ngbot ngbot bot added this to the needsTriage milestone Apr 6, 2023
@dylhunn dylhunn added the cross-cutting: standalone Issues related to the NgModule-less world label Apr 6, 2023
@JeanMeche
Copy link
Member

Hi, there is already an open issue on this : #48607

@ghost
Copy link
Author

ghost commented Apr 6, 2023

yeap you're right. I'll close this one then. I hope we will get it soon

@ghost ghost closed this as completed Apr 6, 2023
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 7, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: forms cross-cutting: standalone Issues related to the NgModule-less world
Projects
None yet
Development

No branches or pull requests

2 participants