为了给出我面临的确切场景,我正在尝试使用 Webpack 将 Zurb 的 Foundation 包捆绑到我的应用程序中。纵观捆绑JS,基金会SCSS是越来越进口的,但我不知道如何将它应用到我的应用程序的渲染。
我require('../../node_modules/foundation.scss/foundation.scss)在根组件的 style 属性中尝试了 a ,这似乎确实设置了该组件的 HTML 的样式,但没有设置任何子组件的 HTML 的样式。
这样做的正确方法是什么?
如果父组件将对象传递给子组件
<child-component [someValue]="someObject"></child-component>
Run Code Online (Sandbox Code Playgroud)
如果子组件修改了someObject,这个改动会反映在父组件上吗?
我对 Angular 2 还是很陌生,无法解决这个问题。
我正在尝试获取用户当前位置并将其坐标保存在名为“location”的变量中。尝试完成此操作时,我收到以下错误消息:

代码如下所示:
import { Component, AfterViewInit } from '@angular/core';
import { AngularFire, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2';
import { AgmCoreModule } from 'angular2-google-maps/core';
@Component({
selector: 'app-home',
templateUrl: './app.home.html',
styleUrls: ['./app.home.css']
})
export class HomeAppComponent {
//restaurants: FirebaseListObservable<any[]>;
zoom: number = 8;
lat: number;
lng: number;
location: any = {};
constructor(private af: AngularFire) {
//this.restaurants = af.database.list('/restaurants');
}
ngAfterViewInit() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(this.setPosition);
}
}
setPosition(position) {
this.location = position.coords;
console.log(position.coords);
}
}
Run Code Online (Sandbox Code Playgroud)
将属性位置设置为以下内容时:
location.lat = …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个树组件,其中od-tree-node组件递归嵌套以构建子节点。我在处理事件时遇到问题。对于叶子节点上的点击事件,鼠标事件总是触发,就好像事件发生在最顶部的组件上一样。我不知道如何处理这个。
预期行为:当用户单击叶/父/根节点时,父组件(例如:)app.component.ts需要知道单击了哪个节点。
当前行为:无论点击哪个节点,都选择根节点(发射到父组件)
plunker : https://plnkr.co/edit/JZTlA5?p=preview
这是模板:
节点.component.html
<!-- parent node -->
<label [attr.for]="resource.resourceType" [class]="cssClasses" *ngIf="resource.hasChildren()" [hidden]="matchedChildrenCount(search, resource) === 0">
<a (click)="toggleNode($event)"> <i [class]="getNodeStateIcon()"></i></a>
<input type="checkbox" *ngIf="showCheckboxes" [checked]="selected">
<a [title]="resource.resourceName" (click)="selectNode($event);">
<i [class]="resource.getIcon()"></i> {{resource.resourceName}} | {{ matchedChildrenCount(search, resource) | lpad : 2 : '0'}}
</a>
</label>
<!-- leaf node -->
<label [attr.for]="resource.resourceType" [class]="cssClasses" *ngIf="!resource.hasChildren()" [hidden]="!isMatched(search, resource)">
<input type="checkbox" *ngIf="showCheckboxes" [checked]="selected">
<a [title]="resource.resourceName" (click)="selectNode($event);">
<i class="icon-status-indicator"></i> {{resource.resourceName}}
<div class="group" *ngIf="resource?.group !== 'Default'">{{resource.group}}</div>
</a>
</label>
<!-- recrusive child …Run Code Online (Sandbox Code Playgroud) “细节”在* ngFor从未来的服务器,是它包含列表。我正在从中选择一个项目。我想让该按钮在用户单击时处于活动状态,并且它应该保持活动状态,直到用户从列表中选择另一个选项。我正在使用[ngClass]但它正在激活一个按钮1 到 2秒。
<ion-list>
<button ion-item [ngClass]="configop.selection" *ngFor="let configop of detail" (click)="itemSelected(configop)" >
<div class="ion-item optionalItem">
<div class="ion-button">
<span class="color-code" >
<img src="{{configop.image}}">
</span>
<span class="color-name">{{ configop.name }}</span>
<span class="color-price">{{ configop.price|currency:'PKR':false }}</span>
</div>
</div>
</button>
</ion-list>
.ts file
itemSelected(configop: any) {
if(this.selection !=null){
if(configop.name == this.selection){
this.storage.remove('carPaint');
this.selection=configop.name;
}
else {
this.storage.remove('carPaint');
this.storage.set('carPaint', configop);
this.selection=configop.name;}
}
else { …Run Code Online (Sandbox Code Playgroud) 嗨,我需要从类型脚本文件中调用一个普通的javascript 函数。
假设我有一个 javascript 文件名test.js并且我已经在应用程序的 index.html 中导入了这个文件。
现在我需要从app.component.ts文件中调用这个test()函数。
function test(){
cosole.log('test');
}
Run Code Online (Sandbox Code Playgroud) 我有 20 个复选框,我需要能够将选中的复选框数量限制为 5/20。根据选中的复选框,它应该隐藏/显示标签。
选中 5 后,不应再选中,而在取消选中 5 或任何后续选中时,它应该允许我再次选中一个不同的框,直到 5 的限制。
我的复选框是使用 angular 指令 *ngFor 生成的,并且会有 5 个答案,因此开始时有 5 个检查。
<div *ngFor="let question of questions; let i = index" class="row container-generic">
<div class="col-md-8">
<div class="container-input-checkbox">
<label class="container-flex">
<input #checkBox class="pvq-create-checkbox" type="checkbox" name="{{i}}" (change)="checkedState($event, checkBox)" [checked]="question.answer">
<div class="pvq-create-label">
<div *ngIf="lang == 'en'">
<p>{{ question.question_EN }}</p>
</div>
<div *ngIf="lang == 'fr'">
<p>{{ question.question_FR }}</p>
</div>
</div>
</label>
<label [@hideShow]="checkBox.checked ? 'show' : 'hide'" >Answer
<input type="textbox" name="" placeholder="{{ question.answer }}">
</label>
</div> …Run Code Online (Sandbox Code Playgroud) 有趣的问题。我需要将 Angualar4 模板与枚举一起使用。
阿卡。
<div class="small-12 columns compliance-freq__item"
[ngClass]="getComplianceFrequencyClasses( complianceFrequency, LicenceComplianceFrequency.QUARTERLY)"</div>
Run Code Online (Sandbox Code Playgroud)
请注意
LicenceComplianceFrequency.QUARTERLY
枚举声明如下
export enum LicenceComplianceFrequency {
QUARTERLY = "QUARTERLY",
MONTHLY = "MONTHLY"
}
Run Code Online (Sandbox Code Playgroud)
这给了我一个模板错误,
无法读取未定义的 QUARTERLY 属性。
我尝试通过修改组件本身以多种方式将其与模板集成。
1) 模板中仍有未定义错误的季度
get LicenceComplianceFrequency() {
return LicenceComplianceFrequency;
}
Run Code Online (Sandbox Code Playgroud)
2)(尖叫 LicenceComplianceFrequency 不是文件 *.ts 的可导出元素)
import {LicenceComplianceFrequency} from '....';
public LicenceComplianceFrequency = LicenceComplianceFrequency;
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?
我正在为我的一个项目使用 angular 2,我正在使用 ngx-pagination 对表进行分页。我的页面结构是这样的
parent->child1=table1
child2-table-2
child-table-3
child4-table-4
Run Code Online (Sandbox Code Playgroud)
每个孩子都调用自己的休息请求并填充表格。我在父级中使用了子组件,如下所示
parent->child1=table1
child2-table-2
child-table-3
child4-table-4
Run Code Online (Sandbox Code Playgroud)
等等
在每个子组件中,我都使用 ngx-pagination 作为
<tr *ngFor="let data of exitProcessPendingList | paginate: { itemsPerPage: 7, currentPage: pgNumber};let i=index">
<pagination-controls (pageChange)="pgNumber = $event"></pagination-controls>
Run Code Online (Sandbox Code Playgroud)
每个孩子都有唯一的 pageNumber 变量;
现在我面临的问题是,当我尝试更改一个表的页码时,它也会影响其他子表。如果我单击第一个表的第 2 页,所有其他表都将当前页更改为第 2 页.我做错了什么?我做的方式有什么问题吗?
angular2-directives angular2-template angular2-services angular
我正在研究 angular 4,我正在尝试实现可以通过单击十字按钮删除标签的功能。所以下面是我的代码:
组件.hmtl
<ul id="ul_top_hypers">
<li *ngFor="let hero of technologies">
<span class="badge badge-pill badge-primary" >{{ hero }}<i class="fa fa-cross-circle-right fa-lg" (click)="removeTag1($event)"></i></span>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
组件.ts
removeTag(event: any) {
console.log(event.target.parentNode.value);
console.log(event.target.value);
}
Run Code Online (Sandbox Code Playgroud)
我想li通过单击十字按钮来获取每个元素的跨度值,以便我可以删除该特定标签。但我正在undefind控制台中。
任何帮助都太可观了。