<div ng-app="ModuleA" ng-controller="MsgController"> <div ng-click="Item1='hi 你好!'">{{ Item1 || "按一下"}}</div> <div> <input type="text" ng-model="say" /> <button ng-click="say='hello 你好!'">按一下</button> </div> <div> {{count || 0}} <button ng-click="count = count + 1">+1</button> </div> <div> <button ng-click="Say()">觸發 controller 中的方法</button> </div> </div>
var moduleA = angular.module("ModuleA",[]); moduleA.controller("MsgController",function($scope) { $scope.Say = function(){ alert('hello'); }; });