无法使用anuglar js更新下拉列表更改指令。 这里是我的应用程序代码angularjs无法更新下拉列表更改指令
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;
}
};
});
这里是小提琴http://jsfiddle.net/Cbqju/
您应该使用像TESTDIR的指令,而不是TESTDIR – user700284
我已经为您创建了plunker HTTP ://plnkr.co/edit/KgcCt43qmEBhvGZaIDsp?p = preview –
@Ajaybeniwal几个疑惑,1)为什么你修改div ..