angularjs - 在自定义工厂服务中使用 $http
问题描述
我的服务有两个功能。一个只是返回一个可以正常工作并完美显示在视图上的字符串。但是另一个函数对后端进行 $http 调用。$http 调用工作正常,但无法将结果拉到控制器
(function(){
var videoStoreApp = angular.module('videoStoreApp', ['ui.router']);
videoStoreApp.factory('videoListService', function($http, $rootScope){
var myService = {};
myService.getData = function()
{
return $http({
method: 'GET',
url: 'app/services/getDvd.php'
}).then(function(data){
var returnObj = {
complete:true,
data: data.data
};
return returnObj;
});
};
myService.getSum = function()
{
return 'services test';
};
return myService;
});
})();
这就是我从控制器调用服务的方式......
angular.module('videoStoreApp').component('videoList', {
templateUrl: 'app/views/videoList.html',
controller: function videoListFunction($http,$scope,videoListService){
$scope.test3 = videoListService.getSum();
$scope.dvd = videoListService.getData();
};
}
});
有人可以帮忙吗。这是我第一次在 stack over flow 上发布问题
解决方案
这是标记
<ul>
<li ng-repeat="dvd in $ctrl.dvd">
<a href="" ng-click="selectMovie(dvd.film_id)">{{dvd.title}}</a>
</li>
</ul>
推荐阅读
- java - 如何读取 gcs 存储桶中的文件内容
- python-3.x - CNN 低准确率猫狗数据集
- excel - 将活动工作表复制到没有公式的新工作簿
- vue.js - CKEditor 5 - VueJS - 当文本字段小于所有项目组合的宽度时,工具栏未包装
- azure - ARM 模板 - 使用 Powershell 传递参数并使用 Secret 值
- r - 从 2 列映射值
- google-maps - 如何免费使用谷歌地图?
- azure - 如何使用 Azure 逻辑应用创建 Blob 容器?
- intellij-idea - IntelliJ 上的 Docker-Plugin 与 VirtualBox 上的 Docker-Daemon 连接时出现问题
- hybris - 如何自定义 b2bacceleratoraddon 插件