我从HTTP调用中获取大量HTML代码.我将HTML块放在一个变量中并使用[innerHTML]将其插入到我的页面中,但我无法设置插入的HTML块的样式.有没有人有任何建议如何实现这一目标?
@Component({selector: 'calendar',
template: '<div [innerHTML]="calendar"></div>',
providers:[HomeService],
styles: [`
h3 {color:red;}
`})
Run Code Online (Sandbox Code Playgroud)
我想要设置样式的HTML是变量"calendar"中包含的块.
我从API获取大量图像URL并将其显示在角度2 Web应用程序中.一些URL被破坏,我想用我本地存储在我的网络服务器上的默认图片替换它们.有没有人有如何测试网址的建议,在状态代码404的情况下,更换损坏的图像?
谢谢!
我尝试从另一个包和文件导入类型时遇到问题.我正在尝试导入的结构是下面的结构.
type PriorityQueue []*Item
type Item struct {
value string
priority int
index int
}
Run Code Online (Sandbox Code Playgroud)
如果我将PriorityQueue与其所有方法放在同一个文件中,我将其声明
pq:= &PriorityQueue{}
Run Code Online (Sandbox Code Playgroud)
我一直在寻找互联网,就像一个疯子,在这个简单的问题上找到答案,但我还没有找到答案.我通常用java编程,导入类是如此基础.
我试图通过角度为2的路由器链接发送一个对象.我为我的人阵列中的每个人对象创建一个人物 - 个人资料组件,并将其显示在我的屏幕上.
<div *ngFor="#person of people; #i = index">
<person-profile [person]="person"></person-profile>
</div>
Run Code Online (Sandbox Code Playgroud)
person-profile组件显示person对象中包含的几条信息.我试图使用路由器链接将人物对象组件中的整个人物对象发送到名为"map"的组件,并将人物对象作为参数传递.
<person-profile>
..code..
<tr>
<td class="category">Address</td>
<td>{{ person.visiting_address }}</td>
<td *ngIf="person.visiting_address"><a [routerLink]="['Map',{person:person}]">View on map</a></td>
</tr>
..code..
<person-profile>
Run Code Online (Sandbox Code Playgroud)
在我的地图组件中,我检索对象:
var person = <any> routeParams.get('person');
Run Code Online (Sandbox Code Playgroud)
问题是我每次都在地图组件中得到同一个人,无论<person-profile>我从哪个执行路由器链接.它始终是人民名单中的第一人.奇怪的是,如果我传递来自person对象的特定参数,它就可以工作.例如,如果我传递person.family_name而不是整个person对象,一切正常,但我想发送整个对象.有什么建议?
谢谢!
这段代码正常工作,我的问题就是原因.我了解到,在阻止之前,您只能将一个值发送到无缓冲的通道.但是在我的代码中,我写了两次,但是来自不同的例行程序,它起作用.如果有人能向我解释原因,我将不胜感激!
func main(){
var ch chan string =make(chan string)
go write(ch)
go write2(ch)
go read(ch)
select{}
}
func write(ch chan string){
for{
ch<-"write1"
}
}
func write2(ch chan string){
for{
ch<-"write2"
}
}
func read(ch chan string){
for{
time.Sleep(time.Second)
select{
case res:= <-ch: fmt.Println(res)
case <-time.After(time.Millisecond*200): fmt.Println("time out")
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个 html 元素,如下所示:
<h1 [style.font-size.em]="mysize" id="title-text" #titleText>{{ screenInfo.title }}</h1>
Run Code Online (Sandbox Code Playgroud)
其中 mysize 是控制 h1 标签字体大小的变量。h1 元素的宽度由内容的字体大小决定。
我得到了对 h1 标签的引用
@ViewChild('titleText') titleTextElement;
Run Code Online (Sandbox Code Playgroud)
如果我运行以下代码,我会得到以下结果
console.log(this.titleTextElement.nativeElement.offsetWidth);
// returns 632px, which is the correct width.
this.mysize *= 0.9;
console.log(this.titleTextElement.nativeElement.offsetWidth);
// returns 632px, but the new width is 572px.
Run Code Online (Sandbox Code Playgroud)
有人能解释为什么这不起作用吗?如果有人可以展示如何获取更新的 offSetwidth 值,我也将不胜感激。