我是angularjs的新手,我试图将数据从函数返回到另一个函数,并将其存储在变量中.
$scope.myNameValidate = function(name){
$scope.friendsList = $scope.getAllFriends(name);
console.log("data", $scope.friendsList);
}
$scope.getAllFriends = function(name){
friendService.getAllfriends(name)
.then(function(data){
//success
console.log(data);
}, function(err){
//error
})
}
Run Code Online (Sandbox Code Playgroud)
我想将所有对象存储在变量中,但结果是未定义的.
在控制台输出
数据未定义
[对象,对象,对象,对象,对象,对象]
我有一个 Angular 应用程序,我试图从应用程序外部(即从 docker compose 文件)设置环境变量。
我指的是下面的文章
https://codinglatte.com/posts/angular/using-os-environment-variables-in-angular-with-docker/
docker-compose.yml
version: '3'
services:
tomcat-server:
image: "tomcat:latest"
ports:
- "8071:8080"
environment:
- API_URL=http://demo-production.com
Run Code Online (Sandbox Code Playgroud)
当我执行以下命令时,我什至可以看到环境变量设置
docker exec -it <dockerName> sh
env
Run Code Online (Sandbox Code Playgroud)
但不知何故,Angular 应用程序没有收到该值,下面是我的 Angular 应用程序代码,按照上面的文章
环境.产品.ts
export const environment = {
production: true,
API_URL: $ENV.API_URL,
TEST_ENV: 'testing'
// API_URL: 'http://production.com'
};
Run Code Online (Sandbox Code Playgroud)
打字.d.ts
declare var $ENV: Env;
interface Env {
API_URL: string
}
Run Code Online (Sandbox Code Playgroud)
自定义-webpack.config.js
const webpack = require('webpack');
module.exports = {
plugins: [
new webpack.DefinePlugin({
$ENV: {
API_URL: JSON.stringify(process.env.API_URL)
}
})
]
};
Run Code Online (Sandbox Code Playgroud)
我用来创建构建的命令 …
我正在尝试禁用基于 PrimeNG 表中的布尔值对选定列进行排序。下面是我的列数组
cols = [
{ field: 'name', header: 'Name', sort: true },
{ field: 'age', header: 'Age', sort: true },
{ field: 'gender', header: 'Gender', sort: false },
{ field: 'status', header: 'Status', sort: false }
];
Run Code Online (Sandbox Code Playgroud)
某些列的sort值为 as false,我需要禁用这些列的排序。
<p-table [columns]="cols" [value]="persons" [resizableColumns]="true" sortField="name" sortMode="single">
<ng-template pTemplate="header" let-columns>
<tr>
<th pResizableColumn *ngFor="let col of columns" [pSortableColumn]="col.field" [pSortableColumnDisabled]="col.field === 'name' || col.field === 'age'">
<div class="tb-heading">{{col.header}}</div>
<div class="sort-icons-container">
</div>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData …Run Code Online (Sandbox Code Playgroud) 我有一个输入文本,该区域如下所示:
<input type="text" [(ngModel)]="areaSearch">
Run Code Online (Sandbox Code Playgroud)
并且,我有一个列表,根据输入的area_name属性区域进行过滤
<ul *ngIf="areaSearch">
<li *ngFor="let area of areaList | filter : {area_name: areaSearch} ">
...
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我得到的错误就像The pipe 'filter' could not be found.任何人都可以帮我解决这个问题吗?
我有一个对象数组,我试图用搜索值过滤它们
component ts
filterArray = [
{'id': 1, 'name': 'ABC', 'type': 'IT'},
{'id': 2, 'name': 'XYZ', 'type': 'Tech'},
{'id': 3, 'name': 'LMN', 'type': 'IT'},
{'id': 4, 'name': 'PQR', 'type': 'Software'},
{'id': 5, 'name': 'JKL', 'type': 'hardware'},
{'id': 5, 'name': 'EFG', 'type': 'hardware'}
];
@ViewChildren('filterRef') filtedItems;
Run Code Online (Sandbox Code Playgroud)
custom pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filter'
})
export class FilterPipe implements PipeTransform {
transform(value: any, args?: any): any {
if (value && args) {
const arr = value.filter((e: any) …Run Code Online (Sandbox Code Playgroud) angular ×3
angular-pipe ×1
angularbuild ×1
angularjs ×1
asynchronous ×1
javascript ×1
primeng ×1
promise ×1