angularjs的$window功能小练习
我们想在一个文本框输入一些文字,然后点击铵钮,alert()出来。
<div ng-app="alertApp" ng-controller="alertController"> <div> <label>Name:</label> <input type="text" ng-model="Name" /> </div> <div> <label></label> <input type="button" value="click me" ng-click="ShowMessage()" /> </div> </div>
var alertApp = angular.module('alertApp', []); alertApp.controller('alertController', function ($scope, $window) { $scope.ShowMessage = function () { if (typeof ($scope.Name) == 'undefined' || $scope.Name == "") { $window.alert("请在Name域中填写名字。"); return; } $window.alert("Hello " + $scope.Name); } });