javascript - 如何将响应正文显示为html

标签 javascript angularjs node.js

我想在我的 html 中将 var maplink 显示为 href。我已经输入了值,结果是我想要显示的 map 链接。我在remoteMethod 中创建了maplink 方法。 map 链接显示在我的控制台中,如何让它显示在 html 中?我想在我的 find-location.html 中显示它 console.png

地理编码.js

angular
.module('app')
.controller('FindLocationController', ['$scope', '$state', 'GeoCode', function ($scope, $state, GeoCode) {
    $scope.GeoCodes = [];

    $scope.submitForm = function () {
        GeoCode
          .geocode({
              address: $scope.geoCode.address,
              zipCode: $scope.geoCode.zipCode,
              city: $scope.geoCode.city,                  
          })
          .$promise
          .then(function () {
              $state.go('find-location');
          });
    };
}])

地理代码.js

    var maplink = "http://maps.google.com/?q=" + lat + "," + lng;
    console.log('maplink is ' + maplink);
    // make a callback function cb
    cb(null, maplink);

远程方法()

      [GeoCode.remoteMethod(
    'geocode', {
      http: {
        path: '/geocode',
        verb: 'post'
      },
      accepts: \[{
        arg: 'address',
        type: 'string',
        required: true
      }, {
        arg: 'city',
        type: 'string',
        required: true
      }, {
        arg: 'zipCode',
        type: 'string',
        required: true
      }\],
      returns: {
        arg: 'maplink',
        type: 'string',
      }
    }
  );

最佳答案

使用 angular.element 方法选择主体并向其附加 map 链接。检查下面的代码。

var maplink = "http://maps.google.com/?q=" + lat + "," + lng;
console.log('maplink is ' + maplink);
// Append maplink to body
var body = angular.element( document.querySelector( 'body' ) );
body.append(maplink);
// make a callback function cb
cb(null, maplink);

关于javascript - 如何将响应正文显示为html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36395736/

相关文章:

javascript - jQuery 菜单目标 - 子菜单无法正常工作

angularjs - Angular 2 ngModel 值使用 ionic 更新速度不够快

Javascript 循环遍历 JSON 对象数组找到实例,但将它们记录为未定义

javascript - 你能结合socket.io的emit功能吗?

javascript - $(.class).eq().append 在工作两次后附加到错误的类

JavaScript For Loop - 有趣,可能很简单

javascript - 在网络上复制游戏内库存

javascript - 无法创建由 AngularJs 注入(inject)的 Bootstrap 轮播

javascript - ng-click 不适用于 ng-if

node.js - 在nodejs中从stdin读取的正确方法