小编mas*_*lek的帖子

如何在 Angular 中使用计算/计算属性?

我被这个问题折磨着:我应该在角度项目中的哪里找到我的计算属性?

例如:我有模型、获取模型的服务和显示模型的组件。

人.模型.ts:

export class Person {
  firstName: string;
  lastName: string;
}
Run Code Online (Sandbox Code Playgroud)

person.service.ts:

export class PersonService {

  // inject http: HttpClient

  get(id) {
   return this.http.get<Person>(`api-endpoint/person/${id}`);
  }
}
Run Code Online (Sandbox Code Playgroud)

person.component.ts

@Component({
  selector: 'app',
  template: `
   <div>
    <input [value]='person.firstName'>
    <input [value]='person.lastName'>
   </div>
`,
  providers:  [ PersonService ]
})
export class AppComponent {
  person: Person;

  // inject personService: PersonService

  ngOnInit() {
   personService.get(1).subscribe(p => this.person = p);
  }
}
Run Code Online (Sandbox Code Playgroud)

现在我需要fullName将其显示到输入字段下的模板中。

选项 1。如果您搜索“角度计算属性”,您很可能会在组件本身中找到具有计算属性的示例。

@Component({
  selector: 'app',
  template: `
   <div>
    <input [value]='person.firstName'>
    <input [value]='person.lastName'> …
Run Code Online (Sandbox Code Playgroud)

binding calculated-field computed-field computed-properties angular

10
推荐指数
1
解决办法
7963
查看次数

以编程方式使用多个Key进行键绑定

绑定CTRL+的方法S

new KeyBinding( SaveCommand, Key.S, ModifierKeys.Control )

for CTRL+ Shift+ S

new KeyBinding( SaveCommand, Key.S, ModifierKeys.Control | ModifierKeys.Shift)

但是,怎么样CTRL+ H+ S?? 有什么建议?

c# wpf key key-bindings modifiers

5
推荐指数
0
解决办法
37
查看次数

如何在浏览器中打开链接?

System.Diagnostics.Process.Start("www.google.com");
Run Code Online (Sandbox Code Playgroud)

它工作得很完美,但只是'google.com'怎么样?

我试着这样做

System.Diagnostics.Process.Start("google.com");
Run Code Online (Sandbox Code Playgroud)

但它不适用于相同的链接并引发异常.有什么建议?

.net c#

1
推荐指数
1
解决办法
82
查看次数

单击后保持打开上下文菜单

我有上下文菜单的datagrid.它以编程方式初始化:

contextMenu = new ContextMenu();

foreach (var col in this.Columns)
{
    var checkBox = new MenuItem()
    {
        Header = col.Header
    };
    Binding myBinding = new Binding("Visibility");
    myBinding.Mode = BindingMode.TwoWay;
    myBinding.Converter = new IsCheckedToVisibilityConverter();
    checkBox.DataContext = col;
    checkBox.SetBinding(MenuItem.IsCheckedProperty, myBinding);
    checkBox.Click += checkBox_Click;
    checkBox.Checked += checkBox_Checked;
    checkBox.Unchecked += checkBox_Unchecked;
    contextMenu.Items.Add(checkBox);

}
Run Code Online (Sandbox Code Playgroud)

它工作得很好,但我想在检查\取消选中菜单项后保持打开上下文菜单.有任何想法吗 ?

c# wpf contextmenu

0
推荐指数
1
解决办法
2195
查看次数