无法使用 anuglar js 更新下拉列表更改的指令。这是我的应用程序代码
html代码
<div ng-app="myApp" ng-controller="MyCtrl">
<select ng-model="opt" ng-options="font.title for font in fonts" ng-change="change(opt)">
</select>
<p>
{{opt}}</p>
<br />
<h3>
Text Is
</h3>
<div id="tstDiv" testdir ct="ct">
</div>
</div>
控制器和指令代码
angular.module("myApp", []).controller("MyCtrl", function ($scope) {
$scope.fonts = [
{ title: "Arial", text: 'Url for Arial' },
{ title: "Helvetica", text: 'Url for Helvetica' }
];
$scope.opt = $scope.fonts[0];
$scope.change = function (option) {
$scope.opt = option;
}
})
.directive("testDir", function ($timeout) {
return {
restrict: 'A',
scope: {
ct: '=ct'
},
link: function ($scope, $elm, $attr) {
document.getElementById('tstDiv').innerHTML = $scope.selectedTitle;
}
};
});