使用Angular 2从按钮的onclick事件创建observable的首选方法是什么?
我不确定在组件代码中从DOM中获取本机元素是否被认为是最佳实践(我该怎么做?),或者如果还有其他一些我不知道的快捷方式.
我已经写了一个基于Spring-boot,tomcat,freemarker的项目,我成功运行它,但每当我修改一些模板和java类时,我必须重新启动服务器或使用Intellij上的"reload changed classes"菜单使更改生效.这浪费了很多时间!
然后我尝试使用springloaded作为官方说:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.0.RELEASE</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/springloaded-1.2.0.RELEASE.jar</systemPath>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
然后我重新运行服务器,但没有按预期工作!在模板或类上进行任何更改后,我仍然需要重新启动服务器.
如何配置springloaded以自动重新加载.非常感谢!
Spring-boot的版本是1.3.0RC1
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.RC1</version>
</parent>
Run Code Online (Sandbox Code Playgroud)
maven版本:3.2 jdk:1.8 intellij:14.1.5 os:windows 8.1 64位
我是nodeJS的新手,通过关注youtube上的预告片开始学习,一切顺利,直到我添加连接功能,如果是mongodb,
mongo.connect("mongodb://localhost:27017/mydb")
Run Code Online (Sandbox Code Playgroud)
当我在cmd(node start-app)上运行我的代码时,得到以下错误,
MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
Run Code Online (Sandbox Code Playgroud)
有人能解释我错过了哪一步吗?我的代码:
var express = require("express");
var MongoClient = require('mongodb');
var url = "mongodb://localhost:27017/mydb";
var webService = require("./webService");
var server = express();
MongoClient.connect(url, function (err, db) {
if (err) throw err;
console.log("Database created!");
db.close();
});
server.use(express.urlencoded({ extended: true }));
server.set('views', __dirname);
server.get('/', function (request, response) {
response.sendFile(__dirname + '/MainPage.html');
});
server.get('/Sign', function (request, response) {
response.render(__dirname + '/Sign.ejs');
});
server.post("/signUp", webService.signUp);
server.post("/createUser", webService.createUser); …Run Code Online (Sandbox Code Playgroud) 我有一个Angular 2应用程序,它使用该ReactiveForms模块来管理使用自定义验证器的表单.验证器接收一个FormControl对象.我有一些输入字段可以使用相同的自定义验证器,只要我知道FormControl传递给验证器时字段的名称.
我找不到任何FormControl公开输入字段名称的方法或公共属性.当然,它很容易看到它的价值.以下显示了我想如何使用它:
public asyncValidator(control: FormControl): {[key: string]: any} {
var theFieldName = control.someMethodOfGettingTheName(); // this is the missing piece
return new Promise(resolve => {
this.myService.getValidation(theFieldName, control.value)
.subscribe(
data => {
console.log('Validation success:', data);
resolve(null);
},
err => {
console.log('Validation failure:', err);
resolve(err._body);
});
});
}
Run Code Online (Sandbox Code Playgroud) 我正在遵循本教程中的转换https://scotch.io/tutorials/angular-2-transclusion-using-ng-content
但是,没有提到如何设置最终替换ng-content的元素.
似乎我只能在css中定位那些元素,如果前面有/deep/关键字,通常在定位嵌套组件时使用.它是否正确?
我有一个提交按钮的表单.该表单调用onclick函数,将某些事件的状态设置为false为true.然后我想将此状态传递回父级,以便如果它为true则呈现componentA但如果为false则呈现componentB.
我怎么做才能做出反应?我知道我需要使用状态或道具,但不知道该怎么做.这也是单向流反应原理的矛盾吗?
ComponentA代码:
<form onSubmit={this.handleClick}>
handleClick(event) {
this.setState({ decisionPage: true });
event.preventDefault();
};
Run Code Online (Sandbox Code Playgroud)
父组件控制它显示的内容:
return (
<div>
{this.props.decisionPage ?
<div>
<LoginPage />
</div>
:
<div>
<Decision showThanks={this.props.showThanks}/>
</div>
}
</div>
)
Run Code Online (Sandbox Code Playgroud) 当我尝试执行npm start时,它可以正常工作,但是当我尝试通过expo运行我的应用程序时,该过程将持续到100%,然后再没有任何反应。我没有得到那儿的确切问题。我在package.json中有以下内容。...请帮助我解决此问题。
{
"name": "ProMeeting",
"version": "0.1.0",
"private": true,
"devDependencies": {
"jest-expo": "~29.0.0",
"react-native-scripts": "^1.14.0",
"react-test-renderer": "16.3.1"
},
"main": "./node_modules/react-native-scripts/build/bin/crna-entry.js",
"scripts": {
"start": "react-native-scripts start",
"eject": "react-native-scripts eject",
"android": "react-native-scripts android",
"ios": "react-native-scripts ios",
"test": "jest"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"@babel/preset-react": "^7.0.0-beta.56",
"expo": "^29.0.0",
"firebase": "^5.3.1",
"native-base": "^2.7.2",
"react": "16.3.1",
"react-native": "^0.55.4",
"react-native-firebase": "^4.3.8",
"react-native-vector-icons": "^5.0.0",
"react-navigation": "^2.11.2"
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Eclipse Java EE IDE并从Eclipse上的Server选项卡启动Tomcat.
Eclipse存储在哪里为JSP文件生成servlet .java文件?我已经检查了Tomcat安装目录,但没有.
谢谢.
我有一个像我这样的小型AngularJs应用程序:
// html
<div ng-repeat="project in projects">
<h3>{{ project.id }}</h3>
<h3>{{ project.title }}</h3>
<div ng-repeat="task in project.tasks">
<h4>{{ task.id }}. {{ task.title }}</h4>
<button class="btn btn-default" ng-click="showEditTask=true">Edit Task</button>
<div class="box row animate-show-hide" ng-show="showEditTask">
<h2>Create a New Task</h2>
<form name="newTaskForm" class="form-horizontal">
Title: <br />
<input ng-model="new_task.title" type="text" id="title" name="title" class="form-control" placeholder="Title" required /><br />
Project: <br />
<select ng-model="new_task.project" ng-options="project.title for project in projects" class="form-control"></select><br>
</form>
<button class="btn btn-success" ng-click="createTask(new_task)" ng-disabled="!newTaskForm.title.$valid">create</button>
</div>
</div>
</div>
// app.js
concernsApp.factory('ConcernService', function ($http, $q) { …Run Code Online (Sandbox Code Playgroud) 我有一个Angular 6应用程序,并编写一些单元测试,试图确定一个元素是否可见,仅仅基于*ngIf指令的布尔结果.
标记:
<div class="header" *ngIf="show">
<div>...</div>
</div>
Run Code Online (Sandbox Code Playgroud)
规范文件:
it('should hide contents if show is false', () => {
const button = debugElement.query(By.css('button')).nativeElement;
button.click(); // this will change show to false
fixture.detectChanges();
expect(debugElement.query(By.css('.header')).nativeElement.style.hidden).toBe(true);
});
Run Code Online (Sandbox Code Playgroud)
我似乎无法hidden从div中获取属性.angular是否使用另一种方法使用*ngIf指令从DOM中隐藏元素?我需要从另一个房产nativeElement?
谢谢!
angular ×4
java ×2
javascript ×2
reactjs ×2
angular-test ×1
angularjs ×1
eclipse ×1
expo ×1
express ×1
jasmine ×1
json ×1
jsp ×1
junit ×1
mongodb ×1
node.js ×1
npm ×1
react-native ×1
rxjs ×1
spring ×1
spring-boot ×1
tomcat ×1
typescript ×1