gpt4 book ai didi

javascript - 使用参数从 Angular Controller 启动功能

转载 作者:行者123 更新时间:2023-11-29 10:32:00 25 4
gpt4 key购买 nike

我需要启动一个函数,该函数需要我得到的 json 中的参数,请求是:

app.controller('getDataCtrl', function ($scope, $http, $ionicLoading) {

$http({
method: "POST",
url: "http://someurl/GetPlaylist",
dataType: "json",
contentType: "application/json; charset=utf-8"
}).then(function mySucces(response) {

$scope.allTracks = response.data;
$scope.recentTracks = response.data.Tracks;
//now i want to luanch the function below that written in a different js file
//and pass parameters
**startCration(recentTracks[0].Song, recentTracks[0].Artist);**

}, function myError(response) {
$scope.allTracks = response.statusText;
});
});

这是我需要启动的功能

function startCration(song, artist) {

MusicControls.create({
track: song,
artist: artist,
}, onCreateSuccess, onCreateError);

但是调用成功后似乎无法调用该函数

最佳答案

当您将所有轨道分配给 $scope.recentTracks 时,您应该引用 $scope.recentTracks 而不仅仅是 recentTracks

startCration(recentTracks[0].Song, recentTracks[0].Artist);

应该是

startCration($scope.recentTracks[0].Song, $scope.recentTracks[0].Artist);

关于javascript - 使用参数从 Angular Controller 启动功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43831577/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com