javascript - 简单的 Angular 代码不起作用

标签 javascript angularjs angularjs-scope angularjs-controller

HTML

<section ng-app="app">
     <table ng-controller="VoicemailsCtrl">
        <caption>{{test}}</caption>
    </table>
</section>

JS

var app = angular.module('app', [])
              .controller('VoicemailsCtrl', ['$scope', VoicemailsCtrl]);

function VoicemailsCtrl($scope, $http)
{
    $scope.vms = [1,2,3];
    $scope.test = 'this is a test';
}

可见于:

http://jsfiddle.net/tx9nbo8g/6/

最佳答案

您错过了添加 ng-app="应用程序" 在部分。

检查更新的 fiddle Fiddle

除此之外,您还需要添加

angular 1.2.1

No wrap in head

在框架和扩展中。 .

关于javascript - 简单的 Angular 代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31594451/

相关文章:

javascript - 在混合应用程序开发中使用本地存储作为 "Local Database"- 危险还是有用?

angularjs - 将通用 Controller 功能存储在服务中,以便将它们置于隔离范围内

javascript - AngularJS 在重复 block 之外和脚本标记中使用 ng-repeat 值

javascript - 基于下划线js的函数转换为PlainJs或jquery

javascript - 如何使用 javascript 禁用单选按钮? (不使用任何 JS 框架)

javascript - Angular Select 不改变模型属性

javascript - 使用按钮 Angular 更改输入日期选择器的值

javascript - JS |将 arrayBuffer 转换为 Uint8ClampedArray 的问题

javascript - CSV 数据导入到可嵌套 json 数据

javascript - 在 Cloudinary 中使用 ngf-resize 上传图像