我正在开发Web应用程序。是否可以使用AngularJS绑定按钮单击上的select元素?
这是我的代码:
<select name="hiatusWeeksSelect" ng-options="weeks.hiatusWeekDates for weeks in schedule.HiatusWeeks" size="11" multiple="multiple" style="width: 80px;margin-left:20px;margin-top:5px;"></select>
答案 0 :(得分:1)
请检查此http://plnkr.co/edit/2ja9TLKf4d7GDtYD7KGv?p=preview
使用ngSanitize
下载文件 - angular-sanitize.js并将其包含在您的应用中。
控制器:
var app = angular.module('myApp', ["ngSanitize"]);
app.controller('myController', function($scope) {
$scope.html = '';
$scope.setHTML = function () {
$scope.html ='<p class="text-color">Your html code</p>'; // You can have your HTML Select code here i.e
//$scope.html ='<select name="hiatusWeeksSelect" ng-options="weeks.hiatusWeekDates for weeks in schedule.HiatusWeeks" size="11" multiple="multiple" style="width: 80px;margin-left:20px;margin-top:5px;"></select>';
}
});
HTML
<body ng-controller="myController">
<span ng-click="setHTML()">Click Me</span>
<p ng-bind-html="html"></p>
</body>