有点卡在这一个,需要使用多部分表单上传图像和json ..不知道如何发送内容类型标题或上传图像..认为我需要转换为blob ..此刻我只是发送我从文件输入字段获得的数据.
任何建议都会非常感谢
$http({
method: 'POST',
url: URL,
headers: { 'Content-Type': false },
transformRequest: function (data) {
console.log(data);
var formData = new FormData();
formData.append("formatteddata", angular.toJson(data.model));
formData.append('media', Image)
return formData;
},
data: { model: shoutoutData, image: shoutoutImage}
}).
success(function (data, status, headers, config) {
alert("success!");
}).
error(function (data, status, headers, config) {
alert("failed!");
});
Run Code Online (Sandbox Code Playgroud) 我知道您可以在模型上使用Validation属性来验证它,如下所示:
public class CommunicationQuery
{
[RegularExpression("[0-9]{0,10}", ErrorMessage = "Please enter a valid policy number")]
public string PolicyId { get; set; }
[RegularExpression("[0-9]{0,10}", ErrorMessage = "Please enter a valid member number")]
public string MemberId { get; set; }
}
public IEnumerable<Communication> Get([FromUri]CommunicationQuery documentQuery)
{
}
Run Code Online (Sandbox Code Playgroud)
但是可以使用诸如此类的验证属性来验证单个字符串吗?
public async Task<HttpResponseMessage> Get([RegularExpression("[0-9]{0,10}")]string id)
{
}
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用.我能够做到这一点的唯一方法是创建一个包装器对象并使用[FromUri],ActionFilterAttribute在操作本身上使用自定义或使用正则表达式手动验证控制器操作中的参数.
我是AngularJS的新手,在理解Angular中的范围概念方面遇到了一些麻烦.我已经阅读了有关stackoverflow以及在线文章的一些帖子,它建议我创建一个自定义指令来创建一个隔离范围,但我无处可去......
至于我正在进行的项目,我试图制作一个按钮,当点击时,将触发textarea.但是,由于ng-repeat,当我只点击一个按钮时,所有按钮都会触发textarea.
我的.js文件:
angular.module('myApp')
.controller('myCtrl', function ($scope, Question) {
scope.visible = false;
scope.toggle = function() {
scope.visible = !scope.visible;
};
.directive("myDirective", function () {
return {
scope: {
ngClick: '&',
ngShow: '&'
}
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的HTML文件:
<ul>
<li ng-repeat="object in objectList">
<button type="text" myDirective ng-click="toggle()">Click</button>
<textarea myDirective ng-show="visible"></textarea>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud) 我有一个在IIS 8.0(arvixe托管)上运行的简单应用程序,它使用AngularJS作为SPA框架.我打开html5mode并将标签链接到index.html(根文件),我还将此文件设置为web.config中的文件.我知道你必须做我所拥有的服务器端重写.
我想要实现的目标如下:
用户输入"domain.com",该网站会加载domain.com/home.当然在URL下实际上是domain.com/index.html/home但是html5mode用重写来处理它.
这是app.config,这很好.
.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider ) {
$routeProvider
.when('/home', {
templateUrl: 'templates/home.html',
controller: 'HomeController'
})
.when('/login', {
templateUrl: 'templates/login.html',
controller: 'LoginController'
})
.when('/forum', {
templateUrl: 'templates/forum.html',
controller: 'ForumController'
})
.when('/rebellinks', {
templateUrl: 'templates/rebellinks.html',
controller: 'RebelLinksController'
})
.when('/events', {
templateUrl: 'templates/events.html',
controller: 'EventsController'
})
.when('/oldnews', {
templateUrl: 'templates/oldnews.html',
controller: 'OldNewsController'
})
.otherwise({
redirectTo: '/home'
});
//use HTML5 History API
$locationProvider.html5Mode(true);
}]);
Run Code Online (Sandbox Code Playgroud)
IIS的Web.Config文件:
<system.webServer>
<rewrite>
<rules>
<clear />
<!--<rule name="jsRule" stopProcessing="true">
<match url=".js" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false"> …Run Code Online (Sandbox Code Playgroud) 我正在努力学习AngularJS.在我跟随导师的时候,我写了与他相同的代码.但是我收到了一个[$injector:undef] Provider 'dataService' must return a value from $get factory method错误.当我在网络中搜索此错误时,会告诉我必须返回一个函数或一个对象.我想我在做.我的工厂声明如下:
module.factory("dataService", ['$http', '$q', function ($http, $q) {
var _topics = [];
var _getTopics = function () {
var deferred = $q.defer();
$http.get("/api/v1/topics?includeReplies=true")
.then(function (result) {
//success
angular.copy(result.data, _topics);
deferred.resolve();
},
function () {
//error
deferred.reject();
});
return deferred.promise;
};
return
{
topics: _topics;
getTopics: _getTopics;
};
}]);
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏......