gpt4 book ai didi

javascript - 如何从 Controller 中的 ng-change 方法将值分配给隔离范围?

转载 作者:行者123 更新时间:2023-11-29 19:10:34 24 4
gpt4 key购买 nike

一旦用户从下拉列表中选择值,我就会调用 ng-change 函数 onSizeChange 并设置 $scope.maxMb $scope.maxBytes 的值$scope.FileSizeString,所以我的问题是,一旦从下拉列表中选择了值,我如何在指令中使用这些值。我试图将这些值绑定(bind)到隔离范围,但没有成功。基本上我需要 fileSizefileValue 大小选择后,我已将其作为属性添加到 html 中的指令,因此这些值应该绑定(bind)到隔离范围,但这种情况正在发生。我怎么能解决这个问题?

指令.js

angular.module("App").directive('progressBarCustom', function() {
return {
restrict: 'E',
scope: {
message: "=",
fileSize: "=",
fileValue: "="
},
templateUrl: '/view/partials/progressbar.html',
controller: "StCtrl",
link: function(scope, el, attrs) {
console.log("file size", scope.fileSize);
//these values should assign to directive template once user select value from dropdown
//start
scope.maxMb = scope.fileSize;
scope.maxBytes = 1000 * 1000 * scope.maxMb;
scope.max = scope.maxBytes;
scope.FileSizeString = scope.fileValue;
// end
el.bind('click', function(event) {
scope.$parent.startRecording();
scope.$parent.stopLogs();
scope.$parent.onSizeChange();
console.log('EVENT', event);
});
};
}
});

控制键

  $scope.onSizeChange = function() {
$scope.maxMb = $scope.selectedFileSize.size;
$scope.maxBytes = 3000;
$scope.max = $scope.maxBytes;
$scope.FileSizeString = $scope.selectedFileSize.value;
console.log('FileSize', $scope.maxMb);
}

main.html

<div class="col-md-3">
<select class="form-control" ng-model="selectedFileSize" ng-options="item as item.value for item in FileSizeOptions" ng-change="onSizeChange()"><option value="">Select</option></select>
</div>

<progress-bar-custom ng-show="progressBarFlag" message="event" fileSize="selectedFileSize.size" fileValue="selectedFileSize.value"></progress-bar-custom>

模板.html

<uib-progressbar type="success" class="progress-striped" max="max" animate="true" value="dynamic"><span>{{downloadPercentage}}%</span></uib-progressbar>
<p class="pull-right bytes-progress-0"><small>Recorded <strong>{{currentBytes}}</strong> of <strong>{{FileSizeString}}</strong></small></p>

最佳答案

将 fileSize 更改为 file-size,将 fileValue 更改为 file-value

<progress-bar-custom ng-show="progressBarFlag"     message="event" file-size="selectedFileSize.size" file-value="selectedFileSize.value"></progress-bar-custom>

与 OP 讨论后更新

只在指令中传递 selectedFileSize 对象,而不是将其作为两个属性发送。您可以从指令中的 selectedFileSize.size 和 selectedFileSize.value 获取值。然后在指令中观察 selectedFileSize 对象

关于javascript - 如何从 Controller 中的 ng-change 方法将值分配给隔离范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39169672/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com