2015-06-14 148 views
0

我只是在玩Ionic/AngularJS。我无法获得警报窗口显示?我开始用空白模板离子。该应用程序实际上在浏览器窗口中启动,但按下按钮时,没有任何反应。Ionic/AngularJS ng-click事件不会触发?

// 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) 
 
{ 
 
\t $scope.refresh = function() 
 
\t { 
 
\t \t window.alert("Hello"); 
 
\t } 
 
});
<!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"> 
 
\t  <h1 class="title">Freshly Pressed</h1> 
 
\t \t <button type="button" class="button" ng-click="refresh()"> 
 
       <i class="icon ion-refresh"></i> 
 
      </button> 
 
\t </ion-header-bar> 
 
\t <ion-content> 
 
\t  <h1>Some Contents</h1> 
 
\t </ion-content> 
 
    </body> 
 
</html>

回答

1

除非离子做的东西比角非常不同,你有data-ng-control,它应该是data-ng-controller

+0

是的。这解决了它。谢谢 ! –