数据绑定Angular js [英] Data binding in Angular js

查看:77
本文介绍了数据绑定Angular js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用角度版本。
https:// ajax。 googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js
我的代码工作正常。但是当我使用这个角度版本时,我的代码无法工作。
https://ajax.googleapis。 com / ajax / libs / angularjs / 1.4.7 / angular.min.js



完整的HTML代码。

 <!DOCTYPE html> 
< html ng-app =>
< script src =https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js\"> ;</script>
< head>
< title> Angular Js教程< / title>
< / head>
< body>
< div ng-controller =Maincontroller>
{{message}}
< / div>
< script>
函数Maincontroller($ scope)
{
$ scope.message =你好吗;
}
< / script>
< / body>
< / html>

我没有输出所需的数据。它只是打印。

  {{message}} 


解决方案

从angular 1.3开始,您无法在全局范围内声明控制器。



<重写你的控制器的声明 MainController

  //声明模块
angular.module('myApp',[]);

//声明控制器
angular.module('myApp').controller('MainController',function($ scope){
$ scope.message =Hii你好吗;
});

关于上述更改,请将< html ng-app = > with < html ng-app =myApp>


When i am using angular version this. "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js" my code works fine. but when i am using this angular version my code is not working. "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js".

Full HTML code.

    <!DOCTYPE html>
    <html ng-app="">
    <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
    <head>
    <title>Angular Js Tutorial</title>
    </head>
    <body>
         <div ng-controller="Maincontroller">
             {{message}}
         </div>
        <script>
             function Maincontroller($scope)
              {
                  $scope.message = "Hii how are you";
              }
        </script>
    </body>
   </html>

I didn't the required output. It simply prints.

   {{message}}

解决方案

Starting from angular 1.3 you can't declare controllers in the global scope.

Rewrite the declaration of your controller MainController

// Declaration of the module
angular.module('myApp', []);

// Declaration of the controller
angular.module('myApp').controller('MainController', function ($scope) {
    $scope.message = "Hii how are you";
});

Regarding to the above changes, replace <html ng-app=""> with <html ng-app="myApp">

这篇关于数据绑定Angular js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆