Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在AngularJS中回调之前如何启动_Javascript_Angularjs - Fatal编程技术网

Javascript 在AngularJS中回调之前如何启动

Javascript 在AngularJS中回调之前如何启动,javascript,angularjs,Javascript,Angularjs,这是我的一段代码: .factory('Latest', function(EBSheadless) { return { posts: function() { // Call the API, and define the specific endpoint return EBSheadlessDrupalAPI.loadEndpoint('views/news.json'); }, post: function(posts,id,call

这是我的一段代码:

.factory('Latest', function(EBSheadless) {
  return {
    posts: function() {
      // Call the API, and define the specific endpoint
      return EBSheadlessDrupalAPI.loadEndpoint('views/news.json');
    },
    post: function(posts,id,callback){
      var findpost = {};
      for(var i=0;i<posts.length;i++) {
        findpost[posts[i].nid] = posts[i];
      }
      callback(findpost[id]);
    }
  };
})
但我需要这样的链接(我无法编辑后端):

因此,我必须在回调中添加
/
。我尝试了很多职位,但都不起作用。
我怎样才能解决它?谢谢

为什么不像这样连接字符串
回调(“/”+findpost[id])
。这将返回
/This-is-a-news

post: function(posts,id,callback){
      var findpost = {};
      for(var i=0;i<posts.length;i++) {
        findpost[posts[i].nid] = posts[i];
      }
      callback("/"+findpost[id]);
}
post:function(posts、id、回调){
var findpost={};
对于(var i=0;i
/this-is-a-news
post: function(posts,id,callback){
      var findpost = {};
      for(var i=0;i<posts.length;i++) {
        findpost[posts[i].nid] = posts[i];
      }
      callback("/"+findpost[id]);
}