如何将所选颜色绑定到 ng-model?

Scrumnoob

我在我的程序中添加了一个颜色选择器,我正在尝试将所选颜色绑定到所选形状。我试图得到它,以便我选择的颜色改变单元格的颜色。{{userSelect}} 是包含所选形状的元素的名称。

Plnkr 链接:https ://plnkr.co/edit/VyyKDYnh2EnJmhiVIO3I ? p = preview



</head>
<body>
  <div class="container-fluid" ng-controller='GameController as vm'>
    <div class="page-header text-center">
      <h1>
        <span class="text-muted">Conway's</span> Game of Life
      </h1>
    </div>
    <table class='grid'>
      <tr ng-repeat="row in vm.board">
        <td ng-repeat="cell in row"
            ng-class="{'alive':cell.isAlive}"
            ng-click="cell.toggle()">

          <span ng-show="cell.isAlive">{{userSelect}}</span>
        </td>
      </tr>
    </table>
    <div>
      <div class="buttons-container">
  <section> 
   <table class="two" border ="1">
              <tr>
                 <td>Cell Shape</td>
                 <td>Cell Color</td>
                 <td>Speed</td>
              </tr>
              <tr>
                 <td>
                      <select ng-model="userSelect">
                      <option value=&#9679>Circle</option>
                      <option value=&#9632>Square</option>
                      <option value=&#9650>Triangle</option>
                      </select>
                 </td>
                  <td>
                   <button ng-model="col"
                           class = "jscolor {
                                         closable:true, closeText:'Close',                
                                         onFineChange:'update(this)',
                                         valueElement:null, value:'FFFFFF'}" 
                           style="border:2px solid black">
                    Cell Color
                  </button>

                  <script>
                    function update(picker) {
                         document.getElementById('1').innerHTML = picker.toHEXString();
                         document.getElementById("col").style.color = picker.toHEXString();
                   }
                  </script>

                 </td>
              </tr>

    </table>
   </section>

      </div>
    </div>
  </div>  
</body>
</html>

乔治亚

HTML 实体需要以分号结尾 (;)

使用ng-style指令设置颜色。

.shape {
   font-size: 30px;
   color: green;
}
<script src="//unpkg.com/angular/angular.js"></script>
  <body ng-app ng-init="userSelect='&#9632;'">
      <input type="color" ng-model="userColor">Pick color {{userColor}}<br>
      <select ng-model="userSelect">
          <option value="&#9679;">Circle</option>
          <option value="&#9632;">Square</option>
          <option value="&#9650;">Triangle</option>
      </select>
      <br>
      userSelect=
      <span class="shape" ng-style="{'color':userColor}">{{userSelect}}</span>
  </body>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章