ng-switch没有生成正确的代码

时间:2017-10-12 12:22:50

标签: javascript angularjs ionic-framework ng-switch

我在离子应用程序中有以下代码,我正在使用离子服务查看应用程序。但是,当第一个ng-switch语句触发..代码

rgb

生成以下代码 - 为什么

rgba

为什么图像源不能通过?

我可以使用ng-switch以外的其他东西吗?

1 个答案:

答案 0 :(得分:1)

你得到了第二个html,因为ng-switch-when =“[]” 下面是相同的工作代码。

  

此代码不适用于angular 1.5.0。请使用角1.6.0

angular.module("myApp", [])
  .controller('MainCtrl', function($scope){
      $scope.postList = ['post1', 'post2'];
      $scope.defaultImage ="https://material.angularjs.org/latest/img/icons/angular-logo.svg";
      $scope.postImage = "https://itxdesign-itxdesign.netdna-ssl.com/wp-content/uploads/2014/01/wordpress-post.jpg";
  })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.min.js"></script>
<div ng-app="myApp">
 <div ng-controller="MainCtrl">
  <select ng-model="selectedPost" ng-options="post for post in postList">
  </select>
  <br>
 -------------------- Switching ---------------
  <div ng-switch on="selectedPost">
      <div ng-switch-when="post1|post2" ng-switch-when-separator="|">                 <img ng-src="{{postImage}}" style="max-width: 90%!important;">
      </div>
      
      <div ng-switch-default>
        <div>Default Image:</div>
        <img ng-src="{{defaultImage}}"style="max-width: 80%!important;"> 
      </div>
  </div>
</div>

相关问题