Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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
AngularJS ng重复数学Pow_Angularjs_Math_Service_Factory_Ng Repeat - Fatal编程技术网

AngularJS ng重复数学Pow

AngularJS ng重复数学Pow,angularjs,math,service,factory,ng-repeat,Angularjs,Math,Service,Factory,Ng Repeat,AngularJS noob在这里。我试图在用户在输入字段中输入一个数字时动态生成一个表,该表按顺序返回10行指数值。例如: <div ng-controller='myController'> <input type="text" ng-model="number"> <table> <tr><th>Index</th><th>Number</th> <tr ng-repeat='item i

AngularJS noob在这里。我试图在用户在输入字段中输入一个数字时动态生成一个表,该表按顺序返回10行指数值。例如:

<div ng-controller='myController'>
<input type="text" ng-model="number">
<table>
<tr><th>Index</th><th>Number</th>
<tr ng-repeat='item in ebooks'><td>{{$index}}</td><td>{{ item.amt}}</td><td> {{ Math.pow(number, $index+1 }}</td>
<td>{{  Math.pow(number,$index+1) * item.amt   }}</td></tr>
</table>
</div>
我试图生成一个表格,其中单元格编号将显示相应的指数编号和另一列,该列将指数编号与项目值相乘。我认为我应该使用服务或工厂,但我不知道什么是正确的方法。我想要的结果是:

 enter number = 5
 Item     Price   Number  Total
  1       0.25    5        1.25
  2       0.1     25        2.5
  3       0.05    125       3.25
在我的服务中,我尝试过这样做:

app.service('MathService', function(){
this.Expo = function (a) {return Math(a, $index +1)};
});
但不是这样的

我读了一些关于在Factory中映射阵列的其他教程,但不理解。 我想我需要在工厂中通过某种方式将Expo键添加到电子书数据集中来创建它,所以它看起来像{item:value,Expo:value}


非常混乱和混乱。救命啊

只需使用
$filter
,如下所示:

.filter('mathPow', function(){
    return function(base, exponent){
        return Math.pow(base, exponent);
    }
})
在您的视图中,您可以这样使用它:

<div ng-controller='myController'>
    <input type="text" ng-model="number">
    <table>
        <tr><th>Index</th><th>Number</th></tr>
        <tr ng-repeat='item in ebooks'>
            <td>{{$index}}</td>
            <td>{{ item.amt}}</td>
            <td>{{ number|mathPow:$index+1 }}</td>
            <td>{{ (number|mathPow:($index+1))*item.amt}}</td>
        </tr>
    </table>
</div>

指数
{{$index}}
{{item.amt}
{{number | mathPow:$index+1}}
{(编号| mathPow:($index+1))*item.amt}

尝试添加$scope.Math=Math;在你的controller@ZackArgyle奥巴马的评论应该是答案。↑↑↑你。是天才!它就像一个符咒!非常感谢。哇!我不知道这样的过滤器。我并不真正理解它是如何工作的,但我会通过更多的阅读来理解它。
<div ng-controller='myController'>
    <input type="text" ng-model="number">
    <table>
        <tr><th>Index</th><th>Number</th></tr>
        <tr ng-repeat='item in ebooks'>
            <td>{{$index}}</td>
            <td>{{ item.amt}}</td>
            <td>{{ number|mathPow:$index+1 }}</td>
            <td>{{ (number|mathPow:($index+1))*item.amt}}</td>
        </tr>
    </table>
</div>