我正在跟进我在http://codepen.io/keval5531/details/LVYROp/
找到的教程因此,我可以在app.js
上提出以下解决方案var app = angular.module('plunker', []);
app.controller('DemoCtrl', function($scope) {
$scope.value = false;
$scope.toggleChange = function(){
if($scope.value == false) {
$scope.value = true;
}
else
$scope.value = false;
console.log('testToggle changed to '+$scope.value);
};
});
现在我在index.html文件中有这个
<!doctype html>
<html ng-app="plunker" >
<head>
<meta charset="utf-8">
<title>AngularJS Plunker</title>
<link rel="stylesheet" href="style.css">
<script src="http://code.angularjs.org/1.2.12/angular-resource.js"></script>
<script src="app.js"></script>
</head>
<body>
<div ng-controller="DemoCtrl">
<br><br>
<ion-toggle ng-model=value ng-change="toggleChange()">Test toggle</ion-toggle>
</div></body>
</html>
这是我制作的插件演示 https://plnkr.co/edit/MUp7QckDCgg50FvcfGeG?p=preview 我的挑战是基于我正在学习的codepen教程,我的显示器上没有任何反应。请帮助!
答案 0 :(得分:0)
这里有几个问题。第一个问题是你没有包含angular.js文件,这是angular的核心,是必需的。此外,您使用的角度源不起作用。这是一个功能齐全的例子
var app = angular.module('plunker', []);
app.controller('DemoCtrl', function($scope) {
$scope.value = false;
$scope.toggleChange = function(){
if($scope.value == false) {
$scope.value = true;
}
else {
$scope.value = false;
console.log('testToggle changed to '+$scope.value);
}
};
});
<!doctype html>
<html ng-app="plunker" >
<head>
<meta charset="utf-8">
<title>AngularJS Plunker</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.12/angular.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.12/angular-resource.js"></script>
</head>
<body>
<div ng-controller="DemoCtrl">
<br><br>
<input type="checkbox" ng-model=value ng-change="toggleChange()">Test toggle</ion-toggle>
</div></body>
</html>
我使用了警报以获得戏剧效果。 问候:)