angularjs - 在 Ionic Typescript 中实现脚本
问题描述
我想为我的 Ionic 应用程序实现动态添加的按钮。我发现我可以使用下面的代码来完成这个任务。
我将代码的第一部分放入 html 正文中的 home.html 文件中。
<div ng-controller="MyCtrl">
<div class="list list-inset">
<div class="item-input" ng-repeat="input in inputs">
<label class="item-input-wrapper">
<input type="text" placeholder="Type something" ng-model="input.value" />
</label>
<button class="button button-small button-balanced" ng-if="$index == inputs.length - 1" ng-click="addInput()">
<i class="icon ion-plus"></i>
</button>
<button class="button button-small button-assertive" ng-if="$index != inputs.length - 1" ng-click="removeInput($index)">
<i class="icon ion-minus"></i>
</button>
</div>
</div>
我放置到 home.ts 文件中的代码的第二部分。我试图将此代码放在主类中。
var app = angular.module('myApp', []);
app.controller("MyCtrl", function($scope) {
$scope.inputs = [{
value: null
}];
$scope.addInput = function() {
console.log("new input");
$scope.inputs.push({
value: null
});
}
$scope.removeInput = function(index) {
$scope.inputs.splice(index, 1);
}
});
不幸的是,我无法定义变量:
var app = angular.module('myApp', []);
因为我收到“打字稿错误”。不幸的是,我不知道如何解决这个问题。我希望你们中的一些人会知道一个解决方案并可以帮助我解决这个问题。
解决方案
推荐阅读
- c - fscanf 仅获取十六进制数的前 4 个字节
- r - R代码将日期范围绘制为许多分类变量的条形或线
- c# - 自适应卡片媒体元素不显示视频
- php - 在 Laravel Eloquent 中自动更新日期时间字段的首选方法是什么
- cakephp - CakePHP 3.x - 保存多对多数据
- xml - 如何在“完成”状态 Odoo 中删除/隐藏“更多”按钮内的“删除”功能
- pandas - 如何在多个条件下使用 pd.read.csv() 读取非常混乱的 .txt 文件
- regex - 我想使用正则表达式获取一些字母
- mysql - 将一列中的值与另一列中的对应值相除
- sql - 如何从平面表中提取层次结构?