相关疑难解决方法(0)

如何将json加载到我的angular.js ng-model中?

我认为这可能是一个非常明显的问题,但我无法在任何地方找到答案.

我只是想从我的服务器加载一些JSON数据到客户端.现在,我正在使用JQuery通过AJAX调用加载它(下面的代码).

<script type="text/javascript">
var global = new Array();
$.ajax({
    url: "/json",
    success: function(reports){
        global = reports;
        return global;
        }
    });
</script>
Run Code Online (Sandbox Code Playgroud)

它位于html文件中.它到目前为止工作,但问题是我想使用AngularJS.现在,当Angular CAN使用变量时,我无法将整个事物加载到变量中,因此我可以为每个循环使用a.这似乎与"$ Scope"有关,它通常位于.js文件中.

问题是我无法将其他页面的代码加载到.js文件中.Angular的每个例子都只显示如下内容:

function TodoCtrl($scope) {
  $scope.todos = [
    {text:'learn angular', done:true},
    {text:'build an angular app', done:false}];
Run Code Online (Sandbox Code Playgroud)

所以,这很有用,如果IA)想要手动输入所有这些,并且B)如果我事先知道我的所有数据是什么......

我事先不知道(数据是动态的),我不想输入它.

因此,当我尝试使用$ Resource将AJAX调用更改为Angular时,它似乎不起作用.也许我无法弄清楚,但它是一个相对简单的GSON数据的GET请求.

tl:dr我无法让AJAX调用工作,以便将外部数据加载到角度模型中.

javascript ajax model angularjs

114
推荐指数
2
解决办法
25万
查看次数

如何使用Angularjs 1.6在同一页面中显示动态内容?

我是Angular的新手.我需要使用AngularJS 1.6从JSON文件渲染动态内容.这就是我所拥有的.

News.json

   {
  "Articles": [
    {
      "Title": "News 1",    
      "Abstract": "News 1 abstract ...",
      "Body": "News 1 starts here.... ",
      "Comments": [
        {
          "comment 1" : "Comment 1 goes here",
          "comment 2" : "Comment 2 goes here",
          "comment 3" : "Comment 3 goes here"
        }]
    },

    {
      "Title": "News 2",
      "Abstract": "News 2 abstract ... ",
      "Body": "News 2 starts here...",
      "Comments": [
        {
          "comment 1" : "Comment 1 goes here",
          "comment 2" : "Comment 2 goes here"
        }] …
Run Code Online (Sandbox Code Playgroud)

html javascript json angularjs

7
推荐指数
1
解决办法
1026
查看次数

标签 统计

angularjs ×2

javascript ×2

ajax ×1

html ×1

json ×1

model ×1