javascript - Ionic/AngularJS ng-click 事件没有触发?

标签 javascript angularjs html css ionic-framework

我只是在玩弄 Ionic/AngularJS。我无法显示警报窗口?我从一个空白模板开始 ionic 。该应用程序实际上在浏览器窗口中启动,但是当按下按钮时,没有任何反应。

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
var App = angular.module('freshlyPressed', ['ionic']);

App.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
});

App.controller( 'AppCtrl' , function($scope, $log)
{
	$scope.refresh = function()
	{
		window.alert("Hello");
	}
});
<!DOCTYPE html>
<html data-ng-app="freshlyPressed" data-ng-control="AppCtrl">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title>Freshly Pressed</title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script> 
  </head>
  <body>
      <ion-header-bar class="bar-balanced">
	      <h1 class="title">Freshly Pressed</h1>
		  <button type="button" class="button" ng-click="refresh()">
              <i class="icon ion-refresh"></i>
          </button>
	  </ion-header-bar>
	  <ion-content>
	      <h1>Some Contents</h1>
	  </ion-content>
  </body>
</html>

最佳答案

除非 Ionic 做了一些与 Angular 非常不同的事情,否则你有 data-ng-control 并且它应该是 data-ng-controller

关于javascript - Ionic/AngularJS ng-click 事件没有触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30825635/

相关文章:

javascript - 如何运行 Google Chrome Headless Puppeteer 代码

javascript - 我如何检查一个数组中的值是否在一个单独的数组中具有特征,如果存在,则在将它们各自转换为新值后返回这些值

javascript - 将字符串作为在 javascript 中创建的动态按钮的 onClick 参数传递

java - 登录页面上的 HTML/JSP/Servlet 问题

html - Outlook 2016 按钮图像显示错误

javascript - 如何通过 Ajax 将带有表单值的 js 对象数组发送到电子邮件

javascript - AngularJS : Trigger $watch in directive when a different element changes

angularjs - Bootstrap 模式中的文本输入未触发 ng-change 事件

angularjs - AngularFire/Firebase - 从 $firebaseArray 获取单个元素以便在 DOM/$remove 中使用

javascript - 在使用 Highcharts 打印之前调整图表大小