小编Sli*_*lip的帖子

ngSwitch如何在Angular2中工作?

我试图在这个例子中使用ngSwitch, 但是我收到一个错误:

在此输入图像描述

我的组件:

  template: `
    <div layout="column" layout-align="center center">   
   <div [ng-switch]="value">
       <div *ng-switch-when="'init'">
     <button md-raised-button class="md-raised md-primary">User</button>
     <button md-raised-button class="md-raised md-primary">Non user</button>

     </div>
  <div *ng-switch-when="0">Second template</div>
  <div *ng-switch-when="1">Third Template</div>
</div>
  </div>`,
    directives: [NgSwitch, NgSwitchWhen, NgSwitchDefault]
 })
Run Code Online (Sandbox Code Playgroud)

我的plunker - wizard.ts

我错过了什么?谢谢

angular2-template angular

25
推荐指数
4
解决办法
6万
查看次数

Ui-sref和md-button.这个怎么运作?

如果我添加ui-sref,为什么菜单项"Menu1"高于其他?

 <md-button  ui-sref="menu1" >Menu1</md-button>
 <md-button>Menu2</md-button>
Run Code Online (Sandbox Code Playgroud)

angularjs angular-material

12
推荐指数
2
解决办法
7840
查看次数

如何在猫鼬中保存对象数组

我从角度来看这个数据

 {
     "name": "Test name",
     "conditions": [
        {
         "id": "56a53ba04ce46bf01ae2bda7",
         "name": "First condition"             
        },
        {
         "id": "56a53bae4ce46bf01ae2bda8",
         "name": "Second condition"
        }
        ],
    "colors": [
        {
         "id": "56a545694f2e7a20064f228e",
         "name": "First color"
        },
        {
         "id": "56a5456f4f2e7a20064f228f",
         "name": "Second color"
        }
        ]
}
Run Code Online (Sandbox Code Playgroud)

我想在mongoDb中的ProductSchema中保存它,但我不知道如何为此创建模式

var ProductSchema = new Schema({
name: String,
conditions:  [Array],
colors: [Array]
          });
Run Code Online (Sandbox Code Playgroud)

以及它如何保存到服务器控制器中的模型

 var product = new Products({
    name: req.body.name,
    conditions: req.body.conditions,
    colors: req.body.colors
});
Run Code Online (Sandbox Code Playgroud)

当我使用这个Schema和这个控制器时,我得到除了name和ObjectId之外的集合中的空记录.如何创建正确的架构和控制器?

mongoose mongodb node.js express

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

如何推入数组?

我想通过angular2(TS)做推车

import {Injectable} from 'angular2/core';    
import {Cart} from './product'; //interface id: Number; name: String

 @Injectable()
 export class ProductService {
 public products;
 public cart : Cart[] = [];

    addToCart(products: Object) {
      console.log('product=',products)
      this.cart.push(this.products);
      console.log('cart=',this.cart);
           }
Run Code Online (Sandbox Code Playgroud)

当我按方法推送产品时,我得到了

product= Object {id: 13, name: "Bombasto"}
Run Code Online (Sandbox Code Playgroud)

但在

console.log('cart=',this.cart);
Run Code Online (Sandbox Code Playgroud)

我有"未定义".为什么?

angular

6
推荐指数
1
解决办法
4万
查看次数

依赖下拉yii2.怎么做?

我可以在yii2中创建一个依赖的下拉列表吗?

我有两张桌子:

'id','name_country"
'id','name_city','country_id'
Run Code Online (Sandbox Code Playgroud)

并在我的模型中有两个方法:

public function getCountryList()
{
$models = NetCountry::find()->asArray()->all();
return ArrayHelper::map($models, 'id', 'country_name');
} 
Run Code Online (Sandbox Code Playgroud)

public function getCityList($parent_id) { 
$models = \common\models\City::find()->where(['parent_id' => $country_id])->asArray()->all();
return ArrayHelper::map($models, 'id', 'name_city','country_id');
}
Run Code Online (Sandbox Code Playgroud)

我有第一个字段:

 <?= $form->field($model, 'country')->dropDownList($model->countryList),['id'=>'parent_id'];
Run Code Online (Sandbox Code Playgroud)

第二个

<?= $form->field($model, 'city')->dropDownList($model->cityList);
Run Code Online (Sandbox Code Playgroud)

我需要'传输' parent_id到控制器并city_list通过AJAX 返回(使用JSON).

我怎样才能做到这一点?我在Yii1中看到了一个例子,但是Yii2怎么样?

yii2

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

.filter不是Angular2的函数

EXCEPTION: TypeError: articles.filter is not a function 我的服务出错了

import {Injectable} from 'angular2/core';
import {Http} from 'angular2/http';
import 'rxjs/Rx';

 @Injectable()

 export class ArticlesService {
     http:Http;
     constructor(http:Http) {
     this.http = http;
    }

getArticle(id: number) {
return Promise.resolve('./articles.json').then(
  articles => articles.filter(article => article.id === id)[0]
     );
  }
 }
Run Code Online (Sandbox Code Playgroud)

我的Plunker但在"英雄之旅"中它运作良好

angular

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