我正在學習角度並嘗試使用控制器,但ng-click不起作用(該函數未被調用)。 Chrome擴展Batarang表示該函數被定義爲null,爲什麼?使用此角度定義功能
angular.module('starter', ['ionic'])
.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();
}
});
})
.controller("TodoControl", function Controller() {
var thisRef = this;
this.todos = [
{
text: "mein todo 1",
done: false
},
{
text: "mein todo 2",
done: true
}
];
this.newEntry = "hallo";
this.AddEntry = function() {
console.log("adding");
thisRef.todos.push({
text: this.newEntry,
done: false
});
thisRef.newEntry = "";
}
});
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic Blank Starter</h1>
</ion-header-bar>
<ion-content>
<div ng-controller="TodoControl as ctr" class="container">
<form role="form">
<div class="form-group" ng-repeat="t in ctr.todos">
<div class="checkbox">
<label class="checkbox-inline">
<input class="form-control todoFormControl" type="checkbox" ng-model="t.done"><span>{{t.text}}</span></label>
</div>
</div>
</form>
<label><input class="todoNewTaskIn" type="text" placeholder="New Task" value="{{ctr.newEntry}}" Style="border: 1px solid gray;" ><button class="button" ng-click="ctr.AddEntry()">Add</button></label>
</div>
</ion-content>
</ion-pane>
</body>
這是離子的應用(這樣的離子包括角被包括)
編輯:這裏一個js小提琴:http://jsfiddle.net/duowfLsn/
把它掛在它會運行一個地方,的jsfiddle例如 –
什麼是HTML文件? – ABOS
http://jsfiddle.net/duowfLsn/ @ patrick-reck –