在控制器中将数据添加到Angular表单(Add data to Angular form in controller)
我是Angular的新手,我正试图让它使用我的API从表单创建一个新的Droplet。 我可以让它正确提交我的表单数据,但我需要为用户ID添加一个隐藏字段。 我假设最好的方法是在将它发送到我的工厂之前在控制器中添加它作为POST请求发送。 我的控制器看起来像这样:
$scope.createNewDroplet = function () { drop.create($scope.drop).success(function(droplet) { $scope.createdDroplet = droplet; }); };
工厂看起来像这样:
app.factory('drop', ['$http', function($http) { return { create: function (drop) { return $http.post('/droplets/', drop) } } }]);
我可以通过$ scope.user.id访问用户ID。 我如何将“user_id:$ scope.user.id”添加到请求中?
I am new to Angular and am trying to get it to create a new Droplet from a form using my API. I can get it to submit my form data correctly but I need to add a hidden field for a user ID. I assume the best way is to add this in the controller before sending it to my factory to be sent as POST request. My controller looks like this:
$scope.createNewDroplet = function () { drop.create($scope.drop).success(function(droplet) { $scope.createdDroplet = droplet; }); };
And the factory looks like this:
app.factory('drop', ['$http', function($http) { return { create: function (drop) { return $http.post('/droplets/', drop) } } }]);
I have access to the user id through $scope.user.id. How would I go about adding "user_id: $scope.user.id" to the request?
原文:https://stackoverflow.com/questions/31337413
最满意答案
正如SpikeX所说,您的服务需要具有对文件夹c:\ Testing的读写权限
用鼠标右键单击该文件夹并更改安全权限。 本地系统帐户的“本地服务”:
或者如果您的服务在特定帐户(例如,您自己的Windows管理员帐户)下运行,请为该帐户写入文件夹的写入权限。
Services.msc中的服务安全选项卡:
I was making a silly mistake. I need to provide file name as well with the path. Its working fine now. Thanks for the responses
相关问答
更多-
要从可执行文件创建Windows服务,可以使用sc.exe : sc.exe create
binPath= " " 您必须在实际的exe路径周围有引号,并且在binPath=之后有一个空格。 关于sc命令的更多信息可以在Microsoft KB251192中找到 。 请注意,对于任何可执行文件,它不起作用:可执行文件必须是Windows服务( 即实现ServiceMain )。 当注册非服务可执行文件作为 ... -
更改配置文件后是否需要重建Windows服务?(Does Windows service needs to be rebuild after changing config file?)[2023-01-29]
如果您指的是自动生成的.config文件,那么不需要重建该服务。 我的猜测是,在上一次迭代中,您忘记了结束标记或其他内容,导致服务无法加载其配置。 If you're referring to the automatically generated .config file, then no, the service need not be rebuilt. My guess is that in your last iteration you forgot an end tag or something, ... -
System.IO.FileSystemWatcher将会诀窍。 Created事件会告诉您何时在您正在观看的目录中创建文件。 要启动转换程序,请查看System.Diagnostics.Process.Start方法。 这两个应用都可以在Windows服务中正常工作。 System.IO.FileSystemWatcher will do the trick. The Created event will tell you when a file has been created in the direc ...
-
现在使用下面的代码每件事都很好 private static void AddtoLogFile(string Message) { string LogPath = @"D:\Logfile\"; string filename = "Log_" + DateTime.Now.ToString("dd-MM-yyyy") + ".txt"; string filepath = LogPath + filename; if (Fil ...
-
public void Start() { FileSystemWatcher fsw = new FileSystemWatcher(); fsw.Path = "\\server\share"; //or use your inputdir fsw.NotifyFilter = NotifyFilters.Size; //(several others available) fsw.Filter = "*.jpg"; fsw.Changed += new Fi ...
-
通过Windows服务创建文件时,访问路径被拒绝(Access to the path is Denied When create file by windows service)[2022-09-01]
服务用户帐户可能无法写入C:\Windows\System32 (它是Windows服务的工作目录)。 无论如何,你不应该写入该文件夹。 它适用于操作系统 - 不是您的服务。 您可以使用Environment.GetFolderPath来获取合适的路径,以便以任何计算机的方式来写入日志文件等文件,而不仅仅是您自己的计算机。 这是一个例子。 var companyPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder ... -
正如SpikeX所说,您的服务需要具有对文件夹c:\ Testing的读写权限 用鼠标右键单击该文件夹并更改安全权限。 本地系统帐户的“本地服务”: 或者如果您的服务在特定帐户(例如,您自己的Windows管理员帐户)下运行,请为该帐户写入文件夹的写入权限。 Services.msc中的服务安全选项卡: I was making a silly mistake. I need to provide file name as well with the path. Its working fine now. ...
-
在Windows服务中的“我的文档”文件夹中创建文件[复制](Create file in My Documents folder from Windows Service [duplicate])[2022-09-11]
我的猜测是Environment.GetFolderPath()返回一个空字符串,因此你的路径变量以'\'开头,它是你的驱动器的根目录。 这可能会发生,因为您以没有定义配置文件的用户身份运行服务。 My guess is that Environment.GetFolderPath() is returning an empty string, therefore your path variable starts with '\' which is the root of your drive. This ... -
Windows服务(windows service)[2022-04-09]
以下是我在创建相同服务时的一些体验(读取和保存网络驱动器上的PDF)。 我有2个驱动器:第一个不需要身份验证,第二个驱动器需要进行身份验证。 映射网络驱动器的常见故障 UNC路径与驱动器盘符:盘符不起作用,您必须使用UNC符号指定路径。 (例如\\ 10.17.194.1 \ RemoteDir \) 身份验证:如果网络驱动器需要您进行身份验证,我找到的唯一方法是在运行该服务的计算机上创建身份验证用户。 如果您需要使用“RemotePassword”作为“RemoteUser”进行身份验证才能访问网络驱动器 ... -
如果您在同一进程中运行Windows服务和WCF服务,则可能是因为您正在重置LogManager.Configuration 。 LogManager的实例可在整个过程中使用。 因此,每次使用new LoggingConfiguration()设置配置时,都会丢失先前的设置配置。 尝试设置一次LogManager.Configuration,然后使用以下方法添加或删除目标: LogManager.Configuration.FindTargetByName(..) LogManager.Configurat ...