在angular2中,我们如何设置/设置对象属性并更新颜色

时间:2018-01-15 09:51:16

标签: angular templates

enter image description here

上面是模板我注意到能够设置note.color = color.color并更新说明我们该怎么做

下面是html代码,注释无法更新为颜色更改:::

<div class="card card-1" *ngFor="let note of notes" style="background:note.color">
    <div style=" background:note.color;margin10px ">
        <img [src]="pinImg" alt='Pin' (click)="pinUnpin(note,true)" />

        <mat-form-field>
            <input contenteditable="true" matInput [(ngModel)]="note.title">
        </mat-form-field>

        <mat-form-field>
            <input contenteditable="true" matInput [(ngModel)]="note.body">
        </mat-form-field>
        <br>
        <div>

            <img [src]="archiveImg" alt='Archive' (click)="archiveUnarchive(note,true)" />
            <img style="width: 15px" [src]="trashImg" alt='Archive' (click)="trashUntrash(note,true)" />
            <ng2-dropdown>
                <ng2-dropdown-button>
                    <img [src]="colorPalet" alt='color palete' />
                </ng2-dropdown-button>
                <ng2-dropdown-menu>
                    <ng2-menu-item *ngFor="let color of colors">

                        <a (click)="updateNote(note)">
                            <img src="{{color.path}}" alt="{{color.color}}" (click)="note.color=color.color ; updateNote(note)" />
                            <!-- click="note.color=color.color" -->
                        </a>
                    </ng2-menu-item>
                </ng2-dropdown-menu>
            </ng2-dropdown>
            <button mat-button class="donebtn" style="width:100px" (click)="updateNote(note)">DONE</button>
        </div>
    </div>
</div>

上面是html代码,注释无法更新为颜色更改:::

2 个答案:

答案 0 :(得分:1)

  

对于同一节点

,不需要两次单击方法

你的问题不明确。但我认为你的两种点击方法存在冲突 尝试:

logits shape Tensor("Placeholder_1:0", shape=(?, 2), dtype=float32)
Saving graph to: /tmp/tmptzko8so7
2018-01-16 17:03:23.257533: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
start 0  batch_size 10
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1323, in _do_call
    return fn(*args)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1302, in _run_fn
    status, run_metadata)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/errors_impl.py", line 473, in __exit__
    c_api.TF_GetCode(self.status.status))
tensorflow.python.framework.errors_impl.InvalidArgumentError: logits and labels must be same size: logits_size=[20,2] labels_size=[10,2]
     [[Node: loss/SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](loss/Reshape, loss/Reshape_1)]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "deep_charging_station_train.py", line 238, in <module>
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "deep_charging_station_train.py", line 227, in main
    train_step.run(feed_dict={x: batch[0], y_: a, keep_prob: 0.5})
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 2042, in run
    _run_using_default_session(self, feed_dict, self.graph, session)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 4490, in _run_using_default_session
    session.run(operation, feed_dict)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 889, in run
    run_metadata_ptr)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1120, in _run
    feed_dict_tensor, options, run_metadata)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1317, in _do_run
    options, run_metadata)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1336, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: logits and labels must be same size: logits_size=[20,2] labels_size=[10,2]
     [[Node: loss/SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](loss/Reshape, loss/Reshape_1)]]

Caused by op 'loss/SoftmaxCrossEntropyWithLogits', defined at:
  File "deep_charging_station_train.py", line 238, in <module>
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/platform/app.py", line 48, in run
    _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "deep_charging_station_train.py", line 192, in main
    logits=y_conv)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/nn_ops.py", line 1783, in softmax_cross_entropy_with_logits
    precise_logits, labels, name=name)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/gen_nn_ops.py", line 4364, in _softmax_cross_entropy_with_logits
    name=name)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
    op_def=op_def)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 1470, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

InvalidArgumentError (see above for traceback): logits and labels must be same size: logits_size=[20,2] labels_size=[10,2]
     [[Node: loss/SoftmaxCrossEntropyWithLogits = SoftmaxCrossEntropyWithLogits[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](loss/Reshape, loss/Reshape_1)]]

注意:请确保您未在​​<a (click)="note.color=color.color ; updateNote(note)"> <img src="{{color.path}}" alt="{{color.color}}" <a/> 方法中更新颜色值

答案 1 :(得分:1)

[style.background] =&#34; note.color&#34; ---&GT;设置卡片/注释的背景颜色

设置note.color :::

<a (click)="updateNote(note)">
    <img src="{{color.path}}" alt="{{color.color}}" (click)="note.color=color.color " />
</a>