我是新角度。我讀了很多博客,關於@/=
之間的指令隔離範圍之間的區別,但我仍然感到困惑。 這是我嘗試過的一個小例子。爲什麼隔離的作用域(=)不能使用字符串?
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Directive Test</title>
<script type="text/javascript">
var app = angular.module('myApp', []);
app.controller('MyCtrl', ['$scope', function ($scope) {
}]);
app.directive('personInfo', [function() {
return {
restrict: 'EA',
scope: {
name: '=',
age: '='
},
template: "My name is {{name}} . My age is {{age}}",
link: function (scope, iElement, iAttrs) {
console.log(scope.name);
}
};
}])
</script>
</head>
<body ng-controller="MyCtrl">
<person-info name="deepak" age="25"></person-info>
</body>
</html>
輸出:
My name is . My age is 25
我沒有得到爲什麼名字是undefined
,其中作爲時代的到來爲25。 當我在做name: @
,一切正常再罰款。
我不知道爲什麼=
作品與數值,但不與strings.I知道用於單向和用於雙向綁定=
@
,但在我的例子,我什麼都沒有做與父母範圍。