如何在 Experirment JavaScript 中编写 Angular Controller in Optimiz



我尝试在优化的实验性JavaScript中编写AngularJS控制器。 它似乎不起作用。

基本上我想插入这样的 HTML 片段

<div ng-app="myApp">
<div ng-controller="MainController">firstApp</div>
</div>

以及如下所示的控制器:

var myApp = angular.module("myApp", []);        
myApp.controller("MainController", function($scope, $window) {
alert("Angularjs call function on page load");
});

我已经尝试了几种方法,但它不起作用,有没有办法让它工作

波兰兹罗提代码:演示

你的 html 应该是

<div ng-app="testApp">
<div ng-controller="MainController">firstApp</div>
</div>

和 js

var myApp = angular.module("testApp", []);        
myApp.controller("MainController", function($scope, $window) {
alert("Angularjs call function on page load");
});

模块应用名称应与 ng-app 相同,ng-controller 的值是你将使用的控制器的名称

最新更新