有模型($範圍)之間的分離和視圖(HTML)。
是的,從視圖中調用$ scope的方法,但這些方法本質上是控制器操作 - 它們是從控制器函數的閉包中執行的。
app.controller('ctrl', function($scope) {
$scope.data = 'hello';
$scope.onclick = function(arg) {
$scope.data = 'hello world!';
}
});
微軟ASPNET MVC是驚人地相似,角MVC:
MVC Controller = ngController
ViewData/ViewBag = $scope
Controller DI = Angular DI in controller function
Razor View Engine = ngRepeat, ngShow, ngModel, etc
RenderActions = Data-driven service-injected directives
RenderPartials = Read-only directives (data retrieved by another controller)
Click triggers controller action = ngClick triggers $scope handler in controller's function closure
Model Data Binding = AngularJS Data Binding
ModelState validation = ngModel validation
HTTP handlers/modules = HTTP interceptors
這讓我不知道如果ASPNET MVC啓發角...
注:的ViewData和$範圍是相似的,但當然,$ scopes通過$ scope繼承來解析$ scope屬性,但在ASPNET MVC中,子ViewData不會從父VIewData繼承。嗯......微軟,這將是一個非常有用的功能:)