angularjs的$window功能小練習

咱們想在一個文本框輸入一些文字,而後點擊銨鈕,alert()出來。



angularjs

<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>
Html Source Code


angularjs 程序:
app

 

 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);
            }           
        });
JS Code


演示:


ide

相關文章
相關標籤/搜索