我有两个对象数组:
我的表的元素不是原始值,而是复杂的对象.
array1 = [obj1,obj2,obj3,obj4]
array2 = [obj5,obj5,obj6,obj7]
Run Code Online (Sandbox Code Playgroud)
我想比较两个数组,看看数组2的元素已经存在于array1中,然后创建一个新的差异数组.
有什么建议吗?
我的Typescript类中有三个变量:
A:number;
B:number;
C:number;
Run Code Online (Sandbox Code Playgroud)
在该类的另一部分,我尝试添加两个变量A和B:
this.C = this.A+this.B; // A =20 and B = 50;
Run Code Online (Sandbox Code Playgroud)
我在html模板中显示C.
<span>{{C}}</span>
Run Code Online (Sandbox Code Playgroud)
我的问题是,而不是添加TWO变量(20+50=70)我得到连接(2050)!
有谁可以帮助我吗 ?
更新:
以下是导致问题的确切代码部分:
goTo(page:number,type:script) {
//
this.pageFirstLineNumber = page;
this.pageLastLineNumber = page + this.LINE_OFFSET; //concatenation!!
}
Run Code Online (Sandbox Code Playgroud)
请注意,pageLastNumber被声明为数字类型,LINE_OFFSET是olso数字类型,我找到了解决此问题但是typescript编译器输出错误(禁止eval):
////
....
this.pageFirstLineNumber = eval(page.toString()); // now It works !!
this.pageLastLineNumber = page + this.LINE_OFFSET; //concatenation!!
Run Code Online (Sandbox Code Playgroud)
UPDATE
这是LINE_OFFSET变量的声明:
private _calculateOffset(fontSize: number) {
let linesDiff = (fontSize * 27) / 14;
let lines:number = 27 - (linesDiff - 27);
this.LINE_OFFSET = Math.floor(lines); …Run Code Online (Sandbox Code Playgroud) 我的HTML中有一个div元素
<div (click) = onPaginationClick()>next</div>
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何将字符串传递给onPaginationlick()函数?当我试图像这样传递它:
<div (click)=onPaginationClick("myString")>next</div>
Run Code Online (Sandbox Code Playgroud)
我有一个解析模板错误.
Enyone可以帮忙吗?
在我的Angular 2应用程序中,我有一个用户列表"用户:任何"包含属性:名称,工作,年龄等等,问题是要获取配置文件图像我必须得到来自的来自Users对象的图像,然后使用web服务getImage(ImageId),所以我在我的html中有这个
<div *ngfor="let user of users">
<img [src]="getImage(user.profileImageId)"/>
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我无法显示配置文件图像,我认为html在数据之前加载?任何帮助?
当我尝试刷新页面时出现此错误:
angular.js:38 http://errors.angularjs.org/1.4.5/ $ injector/modulerr?
P0 = MyApp来&P1 =错误%3A%2 ... ogleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.4.5%2Fangular.min.js%3A19%3A381)
我有一个简单的模块,依赖于ngRoute:
var app = angular.module('myapp', ["ngRoute"]);
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl :'pages/main.html',
controller : 'mainController'
})
.when('/second',{
templateUrl : 'pages/second.html',
controller : 'secondController'
})
});
Run Code Online (Sandbox Code Playgroud)
和我的HTML代码:
<html ng-app='myApp'>
<head><title>The title</title></head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5
/angular.min.js"></script>
<script src="https://code.angularjs.org/1.4.5/angular-route.js">
<script src="app.js"></script>
</script>
<body>
<div ng-view>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 在我的 Angular2 应用程序中,我使用 ngrx 来管理状态,因此当我从服务器接收数据时,我会向减速器分派一个动作。
MyExampleReducer.ts :
export const Reviews: ActionReducer<any> = (state: any[] = [], action: Action) => {
switch (action.type) {
case GET_REVIEWS:
return action.payload;
case ADD_REVIEW :
return [...state, {review : action.payload, replays : []}];
case UPDATE_REVIEW:
return '' // return what ?
case DELETE_REVIEW:
return state.filter(item => {
return item.id !== action.payload.id;
});
default:
return state;
}
};
Run Code Online (Sandbox Code Playgroud)
问题是当我必须更新我的评论数组中的一个项目时,以 redux 方式做的最好方法是什么?
我与实践@Input和@Output在这里是问题.
在我的家庭组件中,我有以下内容:
<!-- Main Content -->
<div class="container">
<div *ngIf="registered">
<login></login>
</div>
<div *ngIf="!registered">
<register></register>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
registered 位于 HomeComponent.ts
@Component({
selector:'home',
templateUrl:'./home.html',
})
export class HomeComponent {
registered:Boolean = true;
}
Run Code Online (Sandbox Code Playgroud)
我的目标是registered根据按下的内容更改主组件中的值.
如果在导航栏中按下了注册表单,则表单将更改为注册表单,因为其中的值home component已更改.但是,如果按下登录,它会返回.
我把它变得有点复杂,但这是为了学习目的.
在目录中user我有三个模块Login,Register和UserService.UserService imports the components from登录and注册and exports them. I importUserService intoNavigationBar`模块.
在home.html我想要更改表单的页面中,我只是调用<nav-bar></nav-bar>
@NgModule({
imports:[
SmartAdminModule,
UserModule //has Login and …Run Code Online (Sandbox Code Playgroud) 我有一个laravel网站,当我使用laravel从数据库加载我的数据时,然后通过这种方式将结果传递给Javascript
<script>
window.forfaits = <?php echo json_encode($results); ?>;
</script>
Run Code Online (Sandbox Code Playgroud)
然后我使用Vue js v-for来显示我的数据.问题是我在Vue Js加载之前在主页上看到插值并且v-cloak无法完成工作,因为我用php获取数据然后传递给js.
我怎样才能在页面上显示插值doest?
UPDATE
通过插值我的意思是:
这是我的main.blade.php文件,它被加载为主页:
<script>
window.forfaits = <?php echo json_encode($forfaits); ?>;
</script>
@extends('layouts.app')
<div>
@section('main-content')
<div class="col-sm-8 col-md-9">
<div id="filter-items">
<div class="product-item offre" v-for="forfait in filteredForfaits">
<div class="product-na">
<h3 class="product-name">@{{forfait.nom_forfait}}</h3>
<div class="product-actions">
............................
Run Code Online (Sandbox Code Playgroud) 我在angular 2应用程序中有两个组件:组件A(父组件)和组件B(子组件).
当我使用@Input()将数据(myData)从A传递到B时,我在我的B(子组件)中获取我的数据,但问题是子组件在myData之前加载并且我得到了undefined,这是一个可以控制台的唯一方法.log(myData)是在ngOnDestroy钩子里!
如何处理这种负载顺序?
在我的Angular 2应用程序中,我有一个功能:
notification : Array<any>;
......
......
getNotification () {
return setTimeout(() => {
this.AppbankService.notify(this.user.NameId)
.subscribe(
(response) => {
if (response.status === 200) {
this.notifications.push(response.json());
console.log(typeof(this.notifications));
}
this.getNotification();
}
)
},5000)}
Run Code Online (Sandbox Code Playgroud)
在这个函数中,我每5秒从服务器收到一次通知,并尝试将它们推送到一个数组,但是有一个:
错误app.module.ts:104错误:TypeError:无法读取未定义的属性'push'(...)
有什么建议吗?
在我的reducer中,我想添加一个像这样的数组元素:
JSON结构(收到http服务):
{
"id": "09fabf9a-e532-4d2a-87cc-bd949a0a437f",
"title": 'my title',
"itemId": "6d442772-d414-46b1-8aab-a105d2bc3b38",
"createdOn": "2017-01-12T10:12:22.987Z",
**"replays": []**
}
Run Code Online (Sandbox Code Playgroud)
所以我想添加(以及为什么不更新)这个重放数组,它位于reviews数组中.
评论阵列:
[review1,review2,review3...review(n)]
Run Code Online (Sandbox Code Playgroud)
我已经有了一个用于管理评论的reducer,但是如何重播 redux方式呢?谢谢
编辑1:减少代码
xport const Reviews: ActionReducer<Array<Review>> = (state: any[] = [], action: Action) => {
switch (action.type) {
case GET_REVIEWS:
return action.payload;
case ADD_REVIEW:
return [...state, action.payload];
case UPDATE_REVIEW:
let index = state.map(review => review.id).indexOf(action.payload.id);
return [
...state.slice(0, index),
Object.assign({}, state[index], action.payload),
...state.slice(index + 1)
];
case DELETE_REVIEW:
return state.filter(item => {
return item.id !== action.payload;
});
case …Run Code Online (Sandbox Code Playgroud) 在Angular应用程序中,我的组件中有这个Observable链:
@Component({
selector: 'app-search',
templateUrl: './search.component.html',
styleUrls: ['./search.component.css']
})
export class SearchComponent implements OnInit {
Run Code Online (Sandbox Code Playgroud)
search.component.ts
results: any[] = [];
queryField: FormControl = new FormControl();
constructor(private _apiService: ApiService) { }
ngOnInit() {
this.queryField.valueChanges
.debounceTime(200)
.distinctUntilChanged()
.switchMap((query) => this._apiService.search(query)) // was subscribe
.subscribe(result => { this.results = result.items; console.log(result); });
Run Code Online (Sandbox Code Playgroud)
}}
seach.ccomponent.html
<input [formControl]='queryField' type="text" id="keyword" autocomplete="off" placeholder="start typing..."/>
Run Code Online (Sandbox Code Playgroud)
我想要做的是取消执行其余的Observables链,如果formControl发出的值为null,则不要转到switchMap操作符(为了不执行请求).
我有这样的数组:
array(2)(
['id'] => "59898441545",
['total'] =>
array(
[0] => 2,
[1] => 5
[2] => 10
[3] => 35
)
);
Run Code Online (Sandbox Code Playgroud)
我希望返回的数组是相同的,但关键的"总数"不是aarray,而是所有的precedemtn值的总和,如下所示:
array(2)(
['id] => "59898441545",
['total'] => 52 // the sum of the precedent elements
);
Run Code Online (Sandbox Code Playgroud)
PS:"总数组"中的元素数量可能会改变任何帮助?thx提前
angular ×8
javascript ×5
arrays ×4
angularjs ×2
ngrx ×2
php ×2
redux ×2
addition ×1
lodash ×1
ng-app ×1
observable ×1
rxjs ×1
typescript ×1
vuejs2 ×1