在Angular中,我想使用ngClass和click事件来切换类.我通过在线查看,但有些是angular1,没有任何明确的指示或示例.任何帮助都感激不尽!
在HTML中,我有以下内容:
<div class="my_class" (click)="clickEvent($event)" ngClass="{'active': toggle}">
Some content
</div>
Run Code Online (Sandbox Code Playgroud)
在.ts:
clickEvent(event){
//Haven't really got far
var targetEle = event.srcElement.attributes.class;
}
Run Code Online (Sandbox Code Playgroud) 所以我通读Bloc
了状态管理flutter
。
由于 Bloc 允许您下沉和流式传输(根据输入重建小部件),那么是否有可能主要使用无状态小部件来构建应用程序?
例如,假设我制作了许多单个无状态类小部件,因此几乎所有东西都被划分为自己的无状态小部件。
使用 Bloc 状态管理,我可以简单地重建某个无状态的子小部件来反映更改。
在这种方法中,我认为不需要使用有状态小部件。当然,作为一个完全的初学者flutter
,我想听听这种方法是否有任何优点。
这是一个好方法吗?任何信息将不胜感激。
我有以下几点TextFormField
:
TextFormField(
focusNode: inputFocusNode,
keyboardType: TextInputType.multiline,
maxLines: null,
minLines: 3,
)
Run Code Online (Sandbox Code Playgroud)
当文本字段处于焦点时,键盘出现。当按下手机后退按钮时,键盘会消失,但文本字段上的光标仍然存在。
我知道你可以FocusScope.of(context).unfocus()
用来移除光标或取消焦点。然而,似乎没有一种直接的方法来检测键盘关闭而不获得包裹
我该如何解决这个问题?
我有以下角度来添加动态加载的内容:
main.html中
<div class="top">
<ng-template #main></ng-template>
</div>
Run Code Online (Sandbox Code Playgroud)
main.ts
import { Component, ViewChild, ComponentFactoryResolver, ViewContainerRef } from '@angular/core';
@Component({
selector: 'page-main_page',
templateUrl: 'main_page.html'
})
export class main_page {
@ViewChild('main', { read: ViewContainerRef }) entry: ViewContainerRef;
data: any;
constructor(public resolver: ComponentFactoryResolver){
};
ngOnInit(){
this.getDynamicREST().then((res)=>{
this.data = res; //Where it is a html markup from php server: <div class="sample"> Example </div>
const factory = this.resolver.resolveComponentFactory(this.data);
this.entry.createComponent(factory);
})
};
}
Run Code Online (Sandbox Code Playgroud)
在getDynamicRest()
,我从PHP服务器获得一个HTML标记,如:
<div class="sample"> Example </div>
Run Code Online (Sandbox Code Playgroud)
但是我收到了一个错误 "Error: No component factory found for …
所以我有一个标题和内容固定高度的单元格(如下所示).
当屏幕尺寸变小时,标题会得到text-overflow:ellipsis;
.
这是我用于标题和内容的标记:
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
Run Code Online (Sandbox Code Playgroud)
然而,对于内容部分(简单div
),内容延伸到容器之外(图中未示出).另外因为内容通常有一个段落,当我应用与上面相同的css标记时,它只是在长行中超出容器而没有break
.
我想要实现的是图像中的最后一部分(红色圆圈).
所以,我已经有了外部细胞max-height
集.我怎样才能使内容保持在单元格内,max-height
并且溢出到下一行并text-overflow: ellipsis;
应用而不是长直线?
多谢你们.
我有以下网址结构.
example.com/items/something_something.
Run Code Online (Sandbox Code Playgroud)
什么是PHP代码来检查该网址包含单词"items"然后显示某些div?
<?php if () { ?> <!--Check if url contains the word "items" -->
Show this
<?php } else { ?>
Don't show this
<?php } ?>
Run Code Online (Sandbox Code Playgroud)
谢谢
我刚开始使用棱角分明的材料.
我有一个空白页面(基本设置)如下:
HTML:
<html lang="en" >
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/1.1.1/angular-material.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body ng-app="BlankApp" ng-cloak>
<!-- No Content -->
<!-- Angular Material Dependencies -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-aria.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-messages.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/1.1.1/angular-material.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
JS:
var app = angular.module('BlankApp', ['ngMaterial']);
Run Code Online (Sandbox Code Playgroud)
很基本的.
当我检查元素时,我得到多个me-theme-style
如下:
我刚开始使用angularjs,我不确定我是否做错了什么.
任何建议将不胜感激!
谢谢!
我有一个简单的 contenteditable 标记:
<div class="example" contenteditable="true">
<div class="inside">Some content</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当我删除“ Some content
”时,class="inside"
div 也会被删除。有没有办法防止删除内容时删除内部div?
例如,这是我在删除内容后尝试制作的外观。
<div class="example" contenteditable="true">
<div class="inside"></div> <!-- The div is not deleted -->
</div>
Run Code Online (Sandbox Code Playgroud)
我环顾四周,但似乎没有明确的答案。
任何帮助都感激不尽。
谢谢你。
我有以下角度:
<div class="test" *ngFor="let item of data; let i = index">
{{item}}
</div>
<div class="function_div" (click)="test(i);">Test Button </div>
Run Code Online (Sandbox Code Playgroud)
然后在.ts
,
export class test{
test(){
console.log(i);
}
}
Run Code Online (Sandbox Code Playgroud)
我想获得一个当前索引号的变量.
我怎样才能获得当前的指数?
谢谢
在 angular 中,如何检测某个元素是否在视图中?
例如,我有以下内容:
<div class="test">Test</div>
Run Code Online (Sandbox Code Playgroud)
有没有办法检测这个 div 何时出现?
谢谢。