小编Zur*_*iel的帖子

类型{}不能分配给类型[]

我是角色的新手,我试图得到一个属性列表,引用我之前已经做过的一些例子.但是我收到一个错误,类型{}不能分配给IProperty[]该行上的类型

this.properties = properties;

.对可能发生的事情做出任何澄清

下面是component.ts

import {Component, OnInit} from '@angular/core';
import {IProperty} from './property';
import {ApiService} from '../api/api.service';

@Component({
    selector:'property',
    templateUrl: '.property.component.html'
})

export class PropertyComponent implements OnInit{
    errorMessage: any;
    properties:IProperty[] = [];

    constructor(private _apiService: ApiService){}

    ngOnInit(){
        this._apiService.getProperties()
        .subscribe(properties => {
            this.properties = properties;
        },
        error => this.errorMessage = <any>error)
    }

    private newFunction() {
        return this.properties;
    }
}
Run Code Online (Sandbox Code Playgroud)

属性接口

export interface IProperty
{
    propertyId: number;
    propertyName: string;
    price: number;
    description: string;
}   
Run Code Online (Sandbox Code Playgroud)

apiService

import {HttpClient, …
Run Code Online (Sandbox Code Playgroud)

typescript angular

2
推荐指数
1
解决办法
1890
查看次数

尝试根据 JSON 字符串值动态设置图标

我有一个位于服务器上的 JSON 格式的客户端配置。

示例 JSON 类似于 { "icon" : "facebook" }

我有下面的小部件。

    class MySocialIcons extends StatelessWidget {

    MySocialIcons({this.icon, this.color});

    final String icon;
    final String color;

    @override
    Widget build(BuildContext context) {

    switch(icon) {
      case 'facebook': {
        return Icon(FontAwesomeIcons.facebook, color: HexColor(color));
      }
      break;

      case 'twitter': {
        return Icon(FontAwesomeIcons.twitter, color: HexColor(color));
      }
      break;

      default: {
        return Icon(FontAwesomeIcons.home, color: HexColor(color));
      }
      break;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法不必为 500 个很棒的字体图标编写 500 个 switch 语句?格式是

FontAwesomeIcons.facebook 我的字符串值“facebook”将附加在 FontAwesomeIcons 的末尾。我正在寻找一种方法来在字符串中写入我想要的任何内容,并且它返回正确的图标小部件。

dart flutter

2
推荐指数
1
解决办法
6153
查看次数

在角度和附加内容中动态更改路线

我已经设置了一个特殊的angular路径,这是许多静态页面的单一路径,(想想隐私策略,客户端html,我希望我的客户能够作为html页面放入一个文件夹,并动态加载它路由.

当您在地址栏中键入内容时,我告诉角色去查看目录并找到带有$ routeParams.name.html文件并加载它.

这很好,但我将数据替换为空白页. blank.html

App.js

.config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);

$routeProvider.when('/test', {
  controller : 'AppRepeatCtrl',
  templateUrl : './templates/test_tpl.html'
}).when('/:name', { 
  controller: 'DynamicRoutes',
  templateUrl: 'partials/blank.html'
}).otherwise({
  redirectTo: '/'
});
Run Code Online (Sandbox Code Playgroud)

})

Controllers.js

function DynamicRoutes ($scope, $http, $location, $route, $routeParams, $compile, appLoading) {
  if ($routeParams.name == '' ) {
     $route.current.templateUrl = 'partials/' + "home.html";
  }  else {
     $route.current.templateUrl = 'partials/' + $routeParams.name + ".html";
  }

  $http.get($route.current.templateUrl).then(function (msg) {
    if (msg.data.contains('html')) {
        $http.get('partials/error.html').then(function (msg) {
            $('#ng-view').html($compile(msg.data)($scope));
        });
    } else { …
Run Code Online (Sandbox Code Playgroud)

routes angularjs angular-routing

1
推荐指数
1
解决办法
3150
查看次数