加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular ng 学习

发布时间:2020-12-17 10:01:07 所属栏目:安全 来源:网络整理
导读:ng-app ng-control ng-model ng-click 等等 ============== var app = angular.module('app',[]); app.controller('MainCtrl',function($scope) { $scope.greet = function() { $scope.message = "Hello," + $scope.user.name; } }); body ng-

ng-app ng-control ng-model ng-click 等等

==============

var app = angular.module('app',[]);

app.controller('MainCtrl',function($scope) {

$scope.greet = function() {

$scope.message = "Hello," + $scope.user.name;

}

});
<body ng-app="app" ng-controller="MainCtrl">

What's your name?:

<input type="text" ng-model="user.name" />

<button ng-click="greet()">Click here!</button>

<h3>{{ message }}</h3>

</body>

==========html tag补充例如pie-chart

<body>

<pie-chart width="400" height="400" data="data"></pie-chart>

</body>

===这个变量必须声明的啊?show=!show,直接每次改变boolean

<button ng-click="show = !show">Show</button>

<div ng-show="show">

I am only visible when show is true. </div>

---<li ng-repeat="person in developers">

{{person.name}} from {{person.country}}

</li>
===这种看起来和任何其他的模版语言没啥差别,可以直接和变量交互


使用Service来进行变量交互

接下来需要借助services来解决这个问题,利用services将user name在controller之间共享。 service==userinformation,函数是初始化函数 app.factory('UserInformation',function() { var user = { name: "Angular.js" }; return user; });

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读