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

[md-input] Impossible to use safe navigation operator? #1073

Closed
vapits opened this issue Aug 18, 2016 · 4 comments
Closed

[md-input] Impossible to use safe navigation operator? #1073

vapits opened this issue Aug 18, 2016 · 4 comments

Comments

@vapits
Copy link

vapits commented Aug 18, 2016

Bug, feature request, or proposal:

Bug (?)

What is the expected behavior?

<md-input [(ngModel)]="activeApp?.name"></md-input> should work.

activeApp is an observarbe in my code:

export class ProjectPropertiesComponent implements OnInit {

  sub: any;
  activeApp: Observable<any>;
  constructor(
    private route: ActivatedRoute,
    private appsService: AppsService) {
    this.route = route;
    this.appsService = appsService;
   }

  ngOnInit() {
    this.getProject();
  }

  getProject() {
    this.sub = this.route.parent.params.subscribe(params => {
      let id = params['id'];
      this.appsService.getApp(id)
        .subscribe(
          data => this.activeApp = data
        );
    });
  }

}

What is the current behavior?

Plunker: http://plnkr.co/edit/Ua7KKEOGCl0nyMzTTwkq?p=preview
(check console)
image

Which versions of Angular, Material, OS, browsers are affected?

Angular version: 2.0.0-rc.5
Angular material versions: 2.0.0-alpha.7-4

Is there anything else we should know?

If I don't use the safe operator it works as it should.

@vapits vapits changed the title [md-input] Impossible to use safe operator? [md-input] Impossible to use safe navigation operator? Aug 18, 2016
@vapits
Copy link
Author

vapits commented Aug 18, 2016

I find out that ? safe-navigation operator can't be used as ng-model does the check, Is that truth? The thing is that this is not working when I'm getting data from a http request, so is this a bug or not?

@vapits
Copy link
Author

vapits commented Aug 18, 2016

Workaround:

In my code I just initialise the property I wanted to display in the md-input in the constructor.

That solved my problem of course. So maybe this is a feature instead of bug.

Please choose and set labels or close the issue.

Thank you

@jelbourn
Copy link
Member

This is the intended behavior of Angular itself (not specific to material). The two-way binding consists of both reading the value and writing the value, where the ?. operator doesn't make sense for assignments.

@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 Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants