过去几天我一直试图在AngularJS中填充文本字段,但无法这样做。我试图通过模态窗口中的abn:树中的选定值填充此字段。
虽然选择显示在模态窗口中,但每当我尝试在父屏幕中显示它时,它都不会做任何事情。
查看:
<label>Category</label>
<div class="input-group">
<input type="text" class="formControl" ng-model="category" required />
<span class="groupButton">
<div ng-controller="ModalCategoryController" >
<script type="text/ng-template" id="ShowCategory.html">
<div ng-include="'tpl/category.html'"></div>
</script>
<button ng-click="open()">...</button>
</div>
</span>
</div>
模板:
<div class="hbox hbox-auto-xs hbox-auto-sm" ng-controller="AbnTreeController">
<div class="col">
<div class="wrapper-md">
<div class="b-a bg-light dk r r-2x">
<abn-tree
tree-data = "fake_data"
tree-control = "fake_tree"
on-select = "fake_handler(branch)"
expand-level = "2"
initial-selection = "Wasif"
>
</abn-tree>
</div>
</div>
</div>
<div>{{output}}</div>
</div>
树
最后,我的树与此类似:
app.controller('AbnTreeController', function($scope, $timeout) {
var fruit_selected, tree, treedata;
$scope.fake_tree_handler = function(branch) {
var _ref;
$scope.result = "selected: " + branch.label;
if ((_ref = branch.data) != null ? _ref.description : void 0) {
return $scope.result += '(' + branch.data.description + ')';
}
};
fruit_selected = function(branch) {
return $scope.result = "apple! : " + branch.label;
};
treedata = [
{
label: 'Fruits',
data: {
bol_value: true
},
onSelect: function(branch) {
return $scope.result = "Fruit: " + branch.data.bol_value;
},
children: [
{
label: 'Apples',
children: [
{
label: 'Wasif',
onSelect: fruit_selected
}]
}
]
}
];
$scope.fake_data = treedata;
$scope.fake_tree = tree = {};
});
每当我在树上选择任何内容时,它都会在对话框中显示,但永远不会填充父窗口中类别字段。