请帮忙"数据ng控制器”;不起作用

Please help "data-ng-controller" is not working

本文关键字:ng 控制器 不起作用 数据 quot      更新时间:2023-09-26

我已经写下了下面的代码,但当我使用"data-ng-controller"时,我的代码就会停止工作,否则它就会工作。请告诉我我的代码出了什么问题。

<!DOCTYPE html>
<html data-ng-app="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>AngularJS | Scope</title>
<link href="style.css" type="text/css" rel="stylesheet" />
<script src="angular.min.js"></script>
</head>
<body>
<div data-ng-controller="Firstfunc">
<input data-ng-model="typename" type="text" /> {{ typename }}
<ul>
<li data-ng-repeat="view in Listing">{{view.name}} - {{view.singh}} </li>
</ul>
</div>
<script>
function Firstfunc ($scope){
$scope.Listing = [
{name:'Ajay Singh', age:'45'},
{name:'Rajeev Arora', age:'75'},
{name:'Nitesh Sharma', age:'26'},
{name:'Kalash Singh', age:'55'}
];
}
</script>

在Angular中,您应该创建一个模块并向其中添加一个控制器。是的,控制器是javascript构造函数,但您已经按照以下格式进行了分配。希望这能有所帮助。

演示在这里

<body data-ng-app="myApp">
    <div data-ng-controller="myController as ctrl">
        <input data-ng-model="typename" type="text" /> {{ typename }}
        <ul>
            <li data-ng-repeat="view in Listing">{{view.name}} - {{view.singh}} </li>
        </ul>
    </div>
</body>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script>
    var app = angular.module("myApp",[]);
    app.controller('myController', function($scope){
        $scope.Listing = [
            {name:'Ajay Singh', age:'45'},
            {name:'Rajeev Arora', age:'75'},
            {name:'Nitesh Sharma', age:'26'},
            {name:'Kalash Singh', age:'55'}
        ];
    })
</script>

我得到了解决方案。

之所以会出现这种情况,是因为我使用的是Angular 1.3v,现在使用的是Angular 1.2.6v,它运行得很好。

感谢大家的回复和支持。