Angularjs 访问ng模型值
请告诉我如何访问控制器中的输入文本框值?您甚至没有注入$scope变量。你想要这样的东西:Angularjs 访问ng模型值,angularjs,Angularjs,请告诉我如何访问控制器中的输入文本框值?您甚至没有注入$scope变量。你想要这样的东西: var app=angular.module('myApp',[]); app.controller("NotesController",function(){ this.allNotes=notes; this.note={}; this.addNewNote=function(){ alert(newNoteText); }; }); 无需在Angular中使用此。
var app=angular.module('myApp',[]);
app.controller("NotesController",function(){
this.allNotes=notes;
this.note={};
this.addNewNote=function(){
alert(newNoteText);
};
});
无需在Angular中使用
此
。您需要注入范围变量:
app.controller('NotesController', function($scope) {
$scope.allNotes=notes;
$scope.note={};
$scope.addNewNote = function(){
alert($scope.newNoteText);
};
});
请参阅我的。无需注入$scope,因为您使用的是controllerAs。只要替换这个:
var app = angular.module('myApp', []);
app.controller("NotesController", function ($scope) {
$scope.allNotes = $scope.notes;
$scope.note = {};
$scope.addNewNote = function () {
console.log($scope.newNoteText);
};
});
ng-model="noteCtrl.newNoteText"
为此:
ng-model="newNoteText"
alert(newNoteText);
在您的控制器中,请更换以下部件:
var app = angular.module('myApp', []);
app.controller("NotesController", function ($scope) {
$scope.allNotes = $scope.notes;
$scope.note = {};
$scope.addNewNote = function () {
console.log($scope.newNoteText);
};
});
ng-model="noteCtrl.newNoteText"
为此:
ng-model="newNoteText"
alert(newNoteText);