gpt4 book ai didi

javascript - ng-click 不在 Ionic 中触发

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:04:16 24 4
gpt4 key购买 nike

这是我的 HTML 代码:

<ion-view view-title="Food Log - {{date | date:'dd/MM/yyyy'}}" ng-controller="FoodLogCtrl">
<div id="foodlog_calorie_progress">
<div>6300</div>
<div>3100</div>
</div>
<div id="foodlog_calorie_text">
<div>
consumed
</div>
<div>
remaining
</div>
</div>
<div id="foodlog_entry_buttons">
<button type="button" ng-click="takePicture()">
<span class="ion-camera"></span>
Capture
</button>
<button>
<span class="ion-images"></span>
Gallery
</button>
</div>
<img ng-repeat="image in images" ng-src="{{urlForImage(image)}}" height="200px" />
<div id="foodlog_overview" class="list">
<a class="item item-icon-left" href="#">
<i class="icon ion-pizza"></i>
Last meal time
<span class="item-note">
1:16 pm
</span>
</a>
<a class="item item-icon-left" href="#">
<i class="icon ion-steam"></i>
Last meal added
<span class="item-note">
Chicken Roll
</span>
</a>
<a class="item item-icon-left" href="#">
<i class="icon ion-medkit"></i>
Last calorie intake
<span class="item-note">
50g
</span>
</a>
</div>
</ion-view>

这是 Controller :

.controller("FoodLogCtrl", function ($scope, $cordovaCamera, $cordovaFile) {
$scope.menuTabShowHide(false);

$scope.images = [];

$scope.takePicture = function () {
alert("asdf");
}

$scope.urlForImage = function(imageName) {
...
}
})

由于某些原因,takePicture 函数不会运行。不过,在运行正常后立即编写 $scope.takePicture()

最佳答案

我让你的代码在这里工作。看看你是否发现了不同的东西。

http://codepen.io/anon/pen/yJWxWY

<html ng-app="ionicApp">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

<title>Ionic Modal</title>

<link href="http://code.ionicframework.com/nightly/css/ionic.css" rel="stylesheet">
<script src="http://code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
</head>


<ion-view view-title="Food Log - {{date | date:'dd/MM/yyyy'}}" ng-controller="FoodLogCtrl">
<div id="foodlog_calorie_progress">
<div>6300</div>
<div>3100</div>
</div>
<div id="foodlog_calorie_text">
<div>
consumed
</div>
<div>
remaining
</div>
</div>
<div id="foodlog_entry_buttons">
<button type="button" ng-click="takePicture()">
<span class="ion-camera"></span>
Capture
</button>
<button>
<span class="ion-images"></span>
Gallery
</button>
</div>
<img ng-repeat="image in images" ng-src="{{urlForImage(image)}}" height="200px" />
<div id="foodlog_overview" class="list">
<a class="item item-icon-left" href="#">
<i class="icon ion-pizza"></i>
Last meal time
<span class="item-note">
1:16 pm
</span>
</a>
<a class="item item-icon-left" href="#">
<i class="icon ion-steam"></i>
Last meal added
<span class="item-note">
Chicken Roll
</span>
</a>
<a class="item item-icon-left" href="#">
<i class="icon ion-medkit"></i>
Last calorie intake
<span class="item-note">
50g
</span>
</a>
</div>
</ion-view>


</html>

和JS

angular.module('ionicApp', ['ionic'])
.controller('FoodLogCtrl', function($scope) {

$scope.takePicture = function () {
alert("take pic");
}

});

如果您仍然无法触发点击事件,则可能是 CSS 问题,并且其他一些元素可能已覆盖在按钮元素上:只是一个想法

关于javascript - ng-click 不在 Ionic 中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39101660/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com