询问时加载值

时间:2017-03-17 06:58:48

标签: javascript jquery angularjs

我有以下代码加载带有值的html。现在,它在开始时加载。但是,我怎样才能在调用函数时加载它。我也将发送一个索引,以便我可以动态发送变量。如何使其适用于此代码?

var app = angular.module("delivcard", []);
app.controller("DelivCtrl", ['$scope', function ($scope) {

  $scope.cards = [{name: 'California Ale Yeast', ferment:'68F - 73F', tolerance: 'High', attenuation: yeastBank[1].attenuation},
  {name: 'California Ale Yeast', ferment:'68F - 73F', tolerance: 'High', attenuation: '73.0% - 80.0%'}];

}]);

我正在尝试从常规javascript文件加载它,但它提供了未定义的$ scope。

function initShopDisplay()
{
    for(var i = 0; i < yeastBank.length; i++)
    {
        if(yeastBank[i].isPrivate == false)
        {
$scope.card();
        }
    }

}

谢谢!

2 个答案:

答案 0 :(得分:0)

只需将代码放入函数中即可,如下所示。

<div class="row" id="ifsc">
  <div class="col-xs-3">

    Correct Bank IFSC
  </div>
  <div class=" col-xs-3">
    <input id="correct_ifsc" type="text" class="form-control" />
  </div>
</div>

调用您想要http://api.techm.co.in/api/v1/ifsc/{IFSCCODE}的功能,或者您可以通过var app = angular.module("delivcard", []); app.controller("DelivCtrl", ['$scope', function ($scope) { $scope.card = function () { $scope.cards = [{name: 'California Ale Yeast', ferment:'68F - 73F', tolerance: 'High', attenuation: yeastBank[1].attenuation}, {name: 'California Ale Yeast', ferment:'68F - 73F', tolerance: 'High', attenuation: '73.0% - 80.0%'}]; } }]);

在html中调用它

答案 1 :(得分:0)

您可以先设置$scope.cards=""然后再写一个函数

var app = angular.module("delivcard", []);
app.controller("DelivCtrl", function ($scope) {

$scope.cards = "";
$scope.card = function ()
{
  $scope.cards = [{name: 'California Ale Yeast', ferment:'68F - 73F', tolerance: 'High', attenuation: yeastBank[1].attenuation},
{name: 'California Ale Yeast', ferment:'68F - 73F', tolerance: 'High', attenuation: '73.0% - 80.0%'}];
}
});

因此,如果你在初始化时调用它,那么在开始时你不会得到未定义的错误。这将在旧浏览器中发生。