我想将函数PhoneList()的数据传递给UI-Router控制器函数到状态' phonedescription'。
JS:
var myApp = angular.module('myApp', ["ui.router"]);
myApp.config(function($stateProvider, $urlRouterProvider){
// For any unmatched url, send to /route1
$urlRouterProvider.otherwise("/phone")
$stateProvider
.state('phone', {
url: "/phone",
templateUrl: "index.html"
})
.state('phonedescription', {
url: "/description",
templateUrl: "description.html",
controller: function($scope){
//Want to access the angular object to pass the attributes to this controller
}
}
});
function PhoneList($scope, $http, $templateCache)
{
$scope.list = function() {
$scope.phones = //get data from backend
}
$scope.list();
};
答案 0 :(得分:0)
您似乎将PhoneList定义为角度框架之外的松散函数。请考虑使用服务。然后,您可以将该服务注入您的phonedescription控制器。