研究了下高大上的AngularJS決定試試它的表單編輯提交功能,據說比JQuery強的不是一星半點。
好奇呀,試試吧。 。 。 。 。搞了好久,尼瑪。 。 。靠。 。靠。 。靠。 。尼瑪。 。靠。 。靠。 。 。 。好吧,誰讓我手欠呢。
搜索到了很多關於AngularJS Form的案例
如:
http://www.angularjs.cn/A08j
https://github.com/tiw/angularjs-tutorial
https://github.com/tiw/angularjs-tutorial/blob/master/ng-form.markdown
https://github.com/tiw/angularjs-tutorial/blob/master/ng-form2.markdown
模仿著我要搞了個AngularJS Form,但是問題來了。 。 。 。
發現初始化時候ng-model 跟input 標籤裡的value 不默契,衝突。 。
後來想再AngularJS controller 裡預先賦值$scope.formData = {'name':'張三'};
可以通過php程序把值賦到這個AngularJS controller裡
複製代碼代碼如下:
<!-- AngularJS controller -->
<script>
var formApp = angular.module('formApp', []);
function formController($scope, $http) {
$scope.formData = {'name':'張三','remark':'備註'};
$scope.myForm = function() {
$http({
method : 'POST',
url : '/role/edit',
data : $.param($scope.formData), // pass in data as strings
headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload)
})
.success(function(data) {
console.log(data);
if (!data.success) {
} else {
}
});
};
}
</script>
<!--對應form裡的input調整-->
<input type="text" name="name" ng-model="formData.name" placeholder="Role Name">
後來又搜啊搜發現還有其他辦法,這麼個東東ng-init=”formData.name='張三'”
複製代碼代碼如下:
<input type="text" name="name" ng-model="formData.name" ng-init="formData.name='張三'" value="">