0
我將AngularJS應用到項目中。
angular.module('xmpl.service', []).
value('objProduct', {
productName: 'ASUS', // this fiel name and value set on angular start!!!!
price: 0, // this fiel name and value set on angular start!!!!
func1: function (setObjProduct) {
this.productName = setObjProduct.productName;
this.price = setObjProduct.price;
},
func2: function (name) {
return this.productName + ' ' + name + '.';
}
}).
value('objCustomer', {
info: function (name) {
this.name = name;
}
});
...
var myApp = angular.module('xmpl', ['xmpl.service', 'xmpl.directive', 'xmpl.filter']).
run(function (objProduct, objCustomer) {
// I hope $.json request to MVC Controller in project will be here
// Object from response go to func1 or func2
// Some test object
var newObjProduct = {
productName: 'SAMSUNG',
price: 400
};
objProduct.func1(newObjProduct);
});
function XmplController($scope, objProduct, objCustomer) {
$scope.greeting = function (value) {
return objCustomer.name + ' ' + value + ' ' + objProduct.productName;
}
$scope.varTest1 = objProduct.productName;
$scope.varFuncTest = function() {
return objProduct.price;
}
}
我嘗試向MVC控制器發送$ .ajax請求,並從響應中獲取一些對象。有任何方法來設置響應對象的字段,並設置名稱和值而不是'productName'和'price'。在BLL中,所有對象都可以改變,我試圖從$ .ajax響應中獲得一些對象,並將它設置爲角度。我應該如何更改代碼?