我有一个Angular 2组件,我想<div id ="myId">通过它的id 检索一个元素div
.我尝试:document.getElementById("myId")在我的组件(TypeScript)中,但我收到一个错误:"找不到名称文档".我看到在其他帖子中我们可以使用@ViewChild做类似的事情,但是我看不出我们如何使用div,任何想法?
我需要通过与其主键不同的键来查询DynamoDB表.我试图为它创建一个全球二级索引.但是我收到此错误:"查询关键条件不支持dynamodb".通过查看一些示例,看起来我不能通过二级索引查询,除非我还包括主索引/键,这是正确的吗?假设我需要查询在某个城市工作的所有员工,我可以在没有employeeID的情况下进行查询吗?
更新的信息 也许我的索引不是应该创建的?
表信息:
GSI:
当我从节点I查询作为参数发送的城市,以及索引名称:
const filter = { city: city};
return this.getRecordsFromDb(filter, { IndexName: "myIndexName" })
.then(records => __.head(records));
Run Code Online (Sandbox Code Playgroud) 我有一个使用Angular-CLI创建的简单应用程序,我想重构并将app.component.ts代码移动到单独的组件文件中并开始出现一个令人讨厌的错误:
找不到模块:错误:无法解析'./sb/sb.component.html'(我的SBComponent).在下面
这就是我所拥有的:
app.module:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { SBComponent } from './sb/sb.component'
@NgModule({
declarations: [
AppComponent, SBComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
app.component:
import { Component } from '@angular/core';
import { NgModule,ElementRef, ViewChild, AfterViewInit} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser' …Run Code Online (Sandbox Code Playgroud) 我有一个mat-tooltip,我通过这样的CSS设计样式:
mat-tooltip .mat-content {
// custom values, styling is not applied
}
Run Code Online (Sandbox Code Playgroud)
但是,自1.1.2角度材料发布以来,这种样式并未应用于我的工具提示.有没有人遇到过类似的问题?
我需要通过脚本任务连接到SQL Server数据库以填充a DataTable,我正在使用ADO.Net提供程序/连接.然而,对于我的生活,我遇到了各种各样的错误.例如,当使用SqlAdapter我得到无效的对象错误时,但是SqlCommand在SSMS中执行没有错误:
SqlConnection conn;
ConnectionManager cm;
SqlCommand cmd;
cm = Dts.Connections["AdoNet"];
conn = (SqlConnection)cm.AcquireConnection(Dts.Transaction);
using (conn)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = queryString;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(myDataTable);
}
Run Code Online (Sandbox Code Playgroud) 我是 Angular 2 的新手,希望得到社区的帮助。我目前正在尝试在<tr>我的 html 视图的元素中实现 ngClass 的动态/条件实现。使用的 trufy 是一个变量,其原始值来自我的 Componenet 上设置的 JSON 对象:
<td [ngClass] = "{weak : {{jsonInMyComponenet.element}}, neutral : !{{jsonInMyComponenet.element}}}" ></td>
Run Code Online (Sandbox Code Playgroud)
当我使用上面的代码时,出现此错误:
得到了预期表达式的插值 ({{}})
如果我删除大括号,我不会出错,但页面不会呈现元素,所以我看不到弱或中性的类实现。我做错了什么?
这可能是一个基本问题,但也许我对c#的了解误导了我.我目前正在尝试在Typescript中引用自定义类型,它只在我实际提供字符串值而不是类型引用时允许它.这就是我所拥有的:
export type MyCustomeType=
'text1' |
'text2' |
'text3';
export class MyCustomeTypeUtils {}
Run Code Online (Sandbox Code Playgroud)
在我的组件中,我声明了我的自定义类型的变量:
var1 : MyCustomeType;
Run Code Online (Sandbox Code Playgroud)
我得到var1的唯一方法就是如果我这样做:
var1 = 'text1'
Run Code Online (Sandbox Code Playgroud)
如果我做
var1 = MyCustomeType.0
Run Code Online (Sandbox Code Playgroud)
要么
var1 = MyCustomeType.text1
Run Code Online (Sandbox Code Playgroud)
它抛出一个错误,它无法找到名称MyCustomeType.任何帮助是极大的赞赏.
我目前正在使用Observable在Angular 2应用程序中获取一些数据,但是我只想在请求完成后发送数据以便在我的模板中显示.我知道有使用"myValue | async"但是为了这个应用程序的目的,我需要捕获变量中的值并将该变量(带有最终值)发送到我的模板.这是我的代码
dataRetrieved() {
this._privateVariable.getData();//this subscribes to an observable
return true;//if the request was completed
}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?谢谢!
更新:
谢谢您的回复.以下是我所拥有的更好的样本:
JSON:
{
"data":
{
"id" : 1,
"dataDescription": "dummy text data to save"
}
}
Run Code Online (Sandbox Code Playgroud)
HTML模板:
<div>[ngmodel] = 'myVariable' </div> <!--myVariable should contain the value of "dataDescription" from my json object. Here when I use the pipe/async instead of a variable I get an error (_myPrivateVariable.myData | async)?.dataDescription -->
Run Code Online (Sandbox Code Playgroud)
MyComponent的:
constructor (private _privateVariable: MyService){}
ngOnInit() {
this._privateVariable.getData();//this retrieves a …Run Code Online (Sandbox Code Playgroud) angular ×5
json ×2
ado.net ×1
angularjs ×1
c# ×1
css ×1
dom ×1
enums ×1
ng-class ×1
observable ×1
rxjs ×1
script-task ×1
sql-server ×1
ssis ×1
typescript ×1