Angulajs系列-01-入门

it2022-05-09  14

1.解决什么问题?

a, controller的各种的创建

b,体验angular的双向绑定

2.怎么解决

2.1 引入angularjs

  下载地址

2.2 创建controller的方法

2.2.1 添加ng-app标识

 

2.2.2 添加controller

<div ng-controller="MyController"> <p>Name:{{user.Name}}</p> <p>Age:{{user.Age}}</p> </div>

 

2.2.3 直接创建

// 直接创建 function MyController($scope) { $scope.text = "234"; $scope.user = { Name: 'test', Age: 18 } }

 

2.2.4 通过数组方式创建

// 通过数组的方式进行创建 var MyController = ['$scope', '$timeout', function ($scope, $timeout) { $scope.user = { Name: 'test', Age: 18 }; $timeout(function () { alert('123'); }, 1000); }];

 

2.2.5 通过inject创建

// 通过inject方式创建 var MyController = function ($scope, $timeout) { $scope.user = { Name: 'test', Age: 18 }; $timeout(function () { alert('123'); }, 1000); }; mycontroller.$inject = ['$scope', '$timeout'];

 

3.源码下载

   https://git.oschina.net/yudaming/Angularjs

4.广告时间 

  觉得还好的话,点个赞关注我哦。

 

转载于:https://www.cnblogs.com/damsoft/p/6013884.html


最新回复(0)