我无法理解如何使用属性选择器来限制控制器的范围.这是最小的控制器代码:
import 'package:angular/angular.dart';
@NgDirective(
selector: '[my-controller]',
publishAs: 'ctrl'
)
class MyController {
String foo = 'fooooooooooooo';
}
main() {
ngBootstrap(module: new Module()
..type(MyController));
}
Run Code Online (Sandbox Code Playgroud)
以下是使用该控制器的视图:
<!DOCTYPE html>
<html>
<body>
<div>
<!-- DOES NOT WORK. MAKES SENSE. -->
<p>Outside ng-app: {{ctrl.foo}}</p>
</div>
<div ng-app>
<div my-controller>
<!-- WORKS. MAKES SENSE -->
<p>Inside my-controller div: {{ctrl.foo}}</p>
</div>
<!-- WORKS. WHY? It is outside the div with the my-controller attribute -->
-->
<p>Outside my-controller div: {{ctrl.foo}}</p>
</div>
<script type="application/dart" src="main.dart"></script>
<script type="text/javascript" src="packages/browser/dart.js"></script> …Run Code Online (Sandbox Code Playgroud) AngularDart ng-repeat指令似乎需要唯一的值; 例如,以下
<li ng-repeat="x in ['Alice', 'Bob', 'Alice']">...</li>
Run Code Online (Sandbox Code Playgroud)
结果是
[NgErr50] ngRepeat error! Duplicates in a repeater are not allowed.
Use 'track by' expression to specify unique keys.
Run Code Online (Sandbox Code Playgroud)
假设字符串列表是从某个外部源获得的,并且不保证值的唯一性,那么如何[NgErr50]避免?
我正在学习飞镖.当我写下一个代码时:
class Hero
{
String name;
Hero(this.name);
}
class AppComponent
{
String title = 'header';
Hero hero = 'Windstorm';
}
Hero hero = new Hero('test');
Run Code Online (Sandbox Code Playgroud)
我收到了错误:
A value of type 'String' cannot be assigned to a variable of type 'Hero'.
我做错了什么?
我们有Dart的Angular 2:
https://github.com/angular/material2/blob/master/README.md#the-goal-of-angular-material
Dart的材质设计组件是否也适用于Angular 2?
我的 Angular 2 Dart 应用程序有许多嵌套组件。如果我的组件之一的某个属性设置为 true,则会显示一个弹出窗口。
如果显示此弹出窗口,我想向文档正文添加一个类。
伪代码示例:
<html>
<head>
</head>
<body class="">
<app-component>
<home-component> <!-- with routers -->
<inner-component>
<popup-component>
// if I am active I want to add a body class
</popup-component>
</inner-component>
</home-component>
</app-component>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
原因很简单:如果显示弹出组件,我想禁用正文滚动 ( overflow-x:hidden;)。bool show_popup如果其中的属性popup_component.dart设置为 true,则会显示弹出组件。
不幸的是,在 CSS 中 - 据我所知 - 没有选择器来检查这个(是否有 CSS 父选择器?) - 否则我会说类似的话
body:has(.my_popup)
Run Code Online (Sandbox Code Playgroud)
在 main.css 文件或类似的文件中。
我怎样才能达到预期的结果?
我有一个Angular Dart页面,我需要在屏幕上为集合中的每个项目创建一个组件.这些项目是自定义模型对象:
class CohortDataSourceAssay{
String name;
String displayName;
bool selected;
List<String> platforms = new List<String>();
CohortDataSourceAssay();
}
Run Code Online (Sandbox Code Playgroud)
我有一个父页面,我想为上面类的集合中的每个元素创建一个模板:
<data-source-assay *ngFor="let assay of dataSource.assays"></data-source-assay>
Run Code Online (Sandbox Code Playgroud)
以下是数据源分析组件的标记:
<div class="dataSourceAssay">
<material-checkbox [(ngModel)]="assay.selected" (ngModelChange)="onCbxChange($event)">{{assay.displayName}}</material-checkbox>
<material-dropdown-select class="selectStyle"
[disabled]="!assay.selected"
[buttonText]="platformLabel"
[selection]="assaySequencingPlatforms"
[options]="sequencingPlatforms"
[itemRenderer]="itemRenderer">
</material-dropdown-select>
</div>
Run Code Online (Sandbox Code Playgroud)
这适用于在dataSource.assays中为每个测定元件加载块,但是测定块似乎不能获得测定模型对象.它似乎是空的.我如何传递它?
我如何从 Dart 中调用这样的代码?
$('.datepicker').datepicker();
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用“package:js/js.dart”包调用函数,如下所示
@JS("Plotly.plot")
external plot(DivElement element, List<PlotData> plotData, Margin margin);
Run Code Online (Sandbox Code Playgroud)
...但是在元素上调用函数?
我目前正在使用dart进行Web开发。使用嘲讽客户端实现服务。但是,发生以下错误。下面的实现代码是一个继承了mockClient的内存中Web api服务。调用client.send()并返回结果的代码。
test_value是json.encode(数据)的结果。
var test_value = '{"id": 1, "type": "Appetizer", "name": "??"}';
return Response (test_value, 200, headers: {'content-type': 'application / json'});
Run Code Online (Sandbox Code Playgroud)
错误
Invalid argument(s): String contains invalid characters.
dart:convert Latin1Codec.encode
package:http/src/response.dart 36:49 new Response
package:basil/common/mock_rest/mock_recipe.dart 40:12 MockRecipe._handler
Run Code Online (Sandbox Code Playgroud)
如果在上述实现代码的名称中放入英语字符串,则不会出现错误。为什么我插入英语以外的其他字符会出现错误?
如果您知道,请告诉我!
在韩国独自奋斗的飞镖程序员
我正在使用useShadowDom: false我的组件试图支持更多的浏览器,而不必使用麻烦的web_components polyfill.启用shadow DOM后,我会做这样的事情:
void onShadowRoot(ShadowRoot root) {
root.querySelector('.btn-go-back').onClick.listen((e) {
if (goBackHandler != null) {
goBackHandler();
}
});
}
Run Code Online (Sandbox Code Playgroud)
onShadowRoot将在我的组件模板加载后运行,因此DOM中存在所有组件元素.如果没有启用Shadow DOM,我会在构造函数中注入组件的根元素,并执行以下操作:
MyComponent(this._root){
_root.querySelector('.btn-go-back').onClick.listen((e) {
if (goBackHandler != null) {
goBackHandler();
}
});
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为组件的模板尚未加载到DOM中,因此根元素还没有任何子查询.
我已经尝试实现AttachAware,并查询方法中的根元素attach(),并且此时也没有加载模板.
所以,如果我没有使用shadow DOM,我怎么知道模板何时加载到DOM中,这样我才能查询组件中的元素?
编辑
如果您尝试查询提供的对象,则尝试使用ShadowRootAware和将导致以下错误:onShadowRootuseShadowRoot: falseShadowRoot
Unsupported operation: Not supported
STACKTRACE:
#0 EmulatedShadowRoot._notSupported (package:angular/core_dom/emulated_shadow_root.dart:5:21)
#1 EmulatedShadowRoot.querySelector (package:angular/core_dom/emulated_shadow_root.dart:32:63)
Run Code Online (Sandbox Code Playgroud)
我也尝试了以下组合:
onShadowRoot,有点,但现在我在控制台输出中看到这个:[WebPlatformShim] WARNING: Failed to set up Shadow DOM shim for …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个代表List<List<int>>Angulardart中的表的表.
这是我的模板文件的内容:
<table>
<tbody>
<tr *ngFor="#row of cells">
<td *ngFor="#cell of row">
<input type="number" #cell (keyup)="0"/>
</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
列表初始化如下:
class Grid {
const GRID_SIZE = 9;
List<List<int>> cells = new List(GRID_SIZE);
Grid() {
cells.forEach((x) => x = new List(GRID_SIZE));
}
}
Run Code Online (Sandbox Code Playgroud)
但是,在渲染的HTML中我只看到9个<tr>空标签,<td>里面没有s.
我错过了什么?