简体   繁体   English

如何使用AngularJS从数据源获取数据?

[英]How to get data from datasource with AngularJS?

Okey, please be patience. Okey,请耐心等待。 I only know jquery and I heard that use AngularJS is something that I should try. 我只知道jquery,听说应该使用AngularJS。

So, what I need to to is visit a page on my local host "../asp/fases/fases-controler.asp" parse the json that this page shows me ( that is something like this: { "fasekind": [ "AAA", "BBB", "CCC" ] } ) and then mount on client side a list like this: 因此,我需要访问本地主机"../asp/fases/fases-controler.asp"上的页面,以解析"../asp/fases/fases-controler.asp"我显示的json(即类似这样的内容: { "fasekind": [ "AAA", "BBB", "CCC" ] } )),然后在客户端安装如下列表:

<ul>
   <li><input type="checkbox" /> <label>AAA</label></li>
   <li><input type="checkbox" /> <label>BBB</label></li>
   <li><input type="checkbox" /> <label>CCC</label></li>
</ul>

I do need a help with this. 我确实需要帮助。 I only know the jQuery way. 我只知道jQuery方式。 I have seen so many tutorials but I don't get it. 我看过太多教程,但我不明白。 I receive always Uncaught ReferenceError: $http is not defined and other erros messages. 我总是收到Uncaught ReferenceError: $http is not defined和其他错误消息。

I don't want someone to do that for me, I just need to figure out how it works. 我不希望有人为我这样做,我只需要弄清楚它是如何工作的。

js controller that I try... it does not work at all. 我尝试的js控制器...根本不起作用。

var app = angular.module("app", []);

app.controller("AppCtrl", function ($http) {
    var app = this;
    $http.get("../asp/fases/fases-controler.asp")
        .success(function (data) {
            app.fases = data;
        })

})

CONTROLLER CONTROLLER

var app = angular.module("app", []);

app.controller("AppCtrl", function ($scope, $http) {

    $http.get("../asp/fases/fases-controler.asp")
        .success(function (data) {
            $scope.fases = data;
        });
});

HTML HTML

<div class="grid-12-12" ng-app='currentApp' ng-controller='ACtrl'>
    <label>Fases <em class="formee-req">*</em>
    </label>
    <ul class="formee-list">
        <li ng-repeat="list in fases">
            <input name="checkbox-01" type="checkbox" />
            <label>{{list}}</label>
        </li>
    </ul>
</div>

JSFIDDLE 的jsfiddle

I found an answer here , it was missing the JSON parse I guess. 我在这里找到了答案,我想它没有JSON解析。 This is what I did: 这是我所做的:

JSON JSON

{
  "fasekind": [ 
              "AAA",
              "BBB",
              "CCC" 
              ]
}

CONTROLLER CONTROLLER

function FetchCtrl($scope, $http) {
        $scope.url = 'fases/fases-controler.asp';

        $http.get($scope.url).success(function (data, status) {
            $scope.fasekind = data.fasekind;
        }).error(function (data, status) {
                $scope.response = 'Request failed';
            });
}

HTML HTML

    <div class="grid-12-12" ng-controller='FetchCtrl'>
        <label>Fases <em class="formee-req">*</em>
        </label>
        <ul class="formee-list">
            <li ng-repeat="foo in fasekind">
                <input name="checkbox-01" type="checkbox" />
                <label>{{foo}}</label>
            </li>
        </ul>
    </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM