作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 angular ui-router 制作 SPA。
这是我的 app.js
var productCatalogApp = angular.module('ProductCatalog', ['ui.router']);
productCatalogApp.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
// route to show our basic form (/form)
.state('wizard', {
url: '/wizard',
templateUrl: 'WizardSubForm',
controller: 'WizardMainController'
})
// nested states
// each of these sections will have their own view
// url will be nested (/form/profile)
.state('wizard.offer', {
url: '/offer',
templateUrl: 'OfferForm',
controller: 'OfferCtrlr'
})
// url will be /form/interests
.state('wizard.customizations', {
url: '/customizations',
templateUrl: 'OfferCustomizations',
controller: 'CustomizationCtrlr',
});
// catch all route
// send users to the form page
$urlRouterProvider.otherwise('/wizard');
public virtual ActionResult OfferCustomizations(string data)
{
OfferCustomization offerCustomization = new OfferCustomization();
//offerCustomization.ProviderId = loginUser.ProviderId;
offerCustomization.ProductCatalogApiUrl = ProductCatalogApiUrl;
return View(offerCustomization);
}
最佳答案
Your question is a bit vague , you need to be more specific on what exactly
you are trying to do.
Generally , this his how you would get data in Angular from the MVC
application.
In Case of MVC/WebAPI , you should use actions to return JSON result back to
the angular service which can then be processed by angular. Example below :
app.factory('myService', function($http) {
var myService = {
GetData: function() {
// $http returns a promise, which has a then function, which also
returns a promise
var promise = $http.get('<ActionURL>').then(function (response) {
// The then function here is an opportunity to modify the response
console.log(response);
// The return value gets picked up by the then in the controller.
return response.data;
});
// Return the promise to the controller
return promise;
}
};
return myService;
});
app.controller('MainCtrl', function( myService,$scope) {
// Call the async method and then do stuff with what is returned inside
our own then function
myService.GetData().then(function(d) {
$scope.data = d;
});
});
After this services is called from the MainCtrl , angular will have the data
from the MVC action available in its $scope.data variable.
关于angularjs - 如何在angular ui-router中将对象发送到操作方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45275470/
我是一名优秀的程序员,十分优秀!