【发布时间】:2014-02-01 22:53:21
【问题描述】:
我找到了很多关于如何将隐藏的输入字段值传递给 angularjs 脚本的资源,但如果该值是从 php 会话中读取的,则不是。
这是我的html代码:
<div ng-controller="ImgCtrl">
<input type="hidden" ng-model="uid" value="<?=$_SESSION["uid"];?>" >
<input type="file" ng-file-select="onFileSelect($files)" >
<br/>
<span>{{ message }}</span>
</div>
我也试过这样:
<input type="hidden" ng-model="uid" value="{{<?=$_SESSION["uid"];?>}}" >
编辑 处理它的 angularjs 代码是:
var ImgCtrl = [ '$scope', '$upload', function($scope, $upload) {
$scope.onFileSelect = function($files) {
for (var i = 0; i < $files.length; i++) {
var file = $files[i];
$scope.upload = $upload.upload({
url: 'image_upload.php',
method: 'POST',
data: {
'uid': $scope.uid
},
file: file
}).success(function(data, status, headers, config) {
$scope.message = data;
}).error(function(data, status) {
alert(data);
});
}
};
}];
这是我找到的答案之一,但我似乎找不到如何在 angularjs 中读取 php 会话变量。
有人有想法吗?
谢谢!
【问题讨论】:
-
您是在尝试将值传递给控制器还是指令? (换句话说,你在用这个值做什么?)
-
我添加了必须处理隐藏值的角度代码...