我有这样的事情:
if(this.selectedItem.label == "str1"
|| this.selectedItem.label == "str2"
|| this.selectedItem.label == "str3"
|| this.selectedItem.label == "str4") {
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否存在更短的语法来使用"this.selectedItem.label"只有一个.
我想知道什么时候应该使用 ngClass 而不是 class 我注意到 css 文件中的这种样式
.someClass {
color: red;
}
<div [ngClass]="['someClass']">Some text</div>
<div class="someClass">Some text2</div>
Run Code Online (Sandbox Code Playgroud)
使用 diff 方法为两个 div 正常工作。我写道,当我们使用条件时,使用 [ngClass] 是一种很好的做法。为什么?使用 [ngClass] 代替 class 有什么好处?
在 MySQL 中,我有创建表的脚本
create table account (
AccountId int not null auto_increment,
Login varchar(31),
Password varchar(31),
primary key (AccountId)
);
Run Code Online (Sandbox Code Playgroud)
在java类中,我有这个表的模型
@Entity
@Table(name = "account")
public class Account {
@Column(name = "AccountId", nullable = false, unique = true)
private Integer AccountId;
private String Login;
private String Password;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer getAccountId() {
return AccountId;
}
Run Code Online (Sandbox Code Playgroud)
在存储库包中
public interface AccountRepository extends JpaRepository<Account, Integer> {
Account findAccountByLoginAndPassword(String login, String password);
}
Run Code Online (Sandbox Code Playgroud)
在客户端站点中,我尝试发送请求登录名和密码,但在服务器站点中出现错误
2018-05-28 14:46:15.464 INFO 20300 --- [nio-8080-exec-2] o.h.h.i.QueryTranslatorFactoryInitiator …Run Code Online (Sandbox Code Playgroud) 我有实体用户
@Entity
@Data
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String username;
private String password;
}
Run Code Online (Sandbox Code Playgroud)
UserRepository
public interface UserRepository extends JpaRepository<UserRepository, Long> {
User findByUsername(String username);
}
Run Code Online (Sandbox Code Playgroud)
调节器
@RestController
@RequestMapping("/user")
public class UserController {
private UserRepository userRepository;
private BCryptPasswordEncoder bCryptPasswordEncoder;
public UserController(UserRepository userRepository, BCryptPasswordEncoder bCryptPasswordEncoder) {
this.userRepository = userRepository;
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
}
@PostMapping("/sign-up")
public void signUp(@RequestBody User user) {
user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
userRepository.save(user);
}
}
Run Code Online (Sandbox Code Playgroud)
在signUp方法中的UserController类userRepository.save(user)throw error类型参数'S'的推断类型'S'不在其范围内; 应该实现'Repository.UserRepository
在角度我在第一个文件中有两个文件
private _test: BehaviorSubject<any> = new BehaviorSubject({});
Run Code Online (Sandbox Code Playgroud)
在第二个文件中
test$: Observable<Object> = this.test2;
Run Code Online (Sandbox Code Playgroud)
当我从_test更改第一个文件.ts变量以测试时,我遇到了错误
Property 'test' is private and only accessible within the class
Run Code Online (Sandbox Code Playgroud)
在一些文章中:
关于_的使用,也已经开发了一个约定,该约定经常被用来作为对象的私有属性或方法的名称的开头。
为什么使用下划线符号项目编译时没有错误?
我是 TypeScript 和 Angular 的新手,我想从本地磁盘加载图像,将此图像存储在变量中并将此数据传递给另一个组件。
有人举了一些例子。我尝试在 Javascript 中使用一个示例,但它在 TypeScrupt 中不起作用。在 HTML 文件中使用这个:
<input type="file" name="img" multiple>
Run Code Online (Sandbox Code Playgroud)
我尝试使用 image 属性,但得到一个未定义的错误。我应该将数组字节传递给另一个组件还是该文件图像的路径?
public onChange(event: Event) {
let files = event.target['files'];
let list: string[];
console.log(files);
for (var i = 0; i < files.length; i++) {
if (FileReader && files && files.length) {
let fileReader = new FileReader();
fileReader.onload = () => {
let infoFile: string = fileReader.result;
list.push(infoFile);
};
fileReader.readAsDataURL(files[i]);
}
}
console.log(list);
let preview = document.querySelector('img');
preview.src = list[0];
};
Run Code Online (Sandbox Code Playgroud)
我在我的component.ts中有方法当我点击输入类型="文件"调用medthod onChange()但是当在控制台中留下循环我有消息表明数组是未定义的.我检查fileReader.result是不是为什么会发生这种情况?如何解决这个问题的一些想法.
是否可以将Angular2与AngularJS混合使用?例如,在AngularJS应用程序中,有一个按钮,单击该按钮时会显示Angular2表单.什么方法合适?我应该在不同的服务器上安装应用程序,还是将Angular2应用程序重写为AngularJS?
我读的比[隐藏]使用*ngIf更好,但在我的情况下,我不想从DOM中删除元素.在component.html我有
<article #articleId id="bodyArticle" [hidden]="isClicked"></article>
Run Code Online (Sandbox Code Playgroud)
在.ts文件中
isClicked = false;
Run Code Online (Sandbox Code Playgroud)
和css
article {
width: 500px;
margin: 0 auto;
background-size: cover;
overflow-wrap: break-word;
justify-content: center;
height: 500px;
overflow-y: scroll;
}
[hidden]{display:none!important}
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题并使该文章不可见?
编辑
现在它正在工作,但现在我尝试使用
var myArticle = document.querySelector('article');
myArticle.textContent = this.imageService.getBodyRes();
Run Code Online (Sandbox Code Playgroud)
我有错误,未定义如果文章不从DOM中删除,为什么会发生这种情况?
它是如何工作的例子;
let x;
console.log(x || 2); // 2
Run Code Online (Sandbox Code Playgroud)
如果
let x = 4;
console.log(x || 2); // 4
Run Code Online (Sandbox Code Playgroud)
如果
let x = 5;
let y = 7;
console.log( y || x || 2);
Run Code Online (Sandbox Code Playgroud)
这是指console.log()写第一个值是真的吗?
angular ×6
javascript ×6
typescript ×5
html ×3
css ×2
java ×2
spring-boot ×2
angularjs ×1
spring ×1
spring-data ×1