λ΄ μ½λλ λ€μκ³Ό κ°μ΅λλ€.
one_time.js
var sample = angular.module('sample', []);
sample.controller('OneTimeController', function () {
this.name = 'John';
this.blah = 'sdflk';
});
index.html
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script type="text/javascript" src="one_time.js"></script>
</head>
<body ng-app="sample">
<div ng-controller="OneTimeController as test">
<p>Input something in the input box:</p>
<p>Name: <input type="text" ng-model="test.name" value="John"></p>
<p ng-bind="test.name"></p>
<p ng-bind="::test.name"></p>
<p ng-if="test.name && test.blah">testing</p> <!-- works perfectly-->
<p ng-if="::test.name && test.blah">testing with first expression as one time binded</p> <!-- works but the second property is not one time binded-->
<p ng-if="::test.name && ::test.blah">testing with one time bind</p><!-- doesn't work throws syntax error-->
</div>
</body>
</html>
name μμ±μ ν λ² λ°μΈλ©νλ €λ ng-if μ‘°κ±΄μ΄ μλ <p>
νκ·Έλ₯Ό νμνλ €κ³ ν©λλ€. λλ κ·Έκ²μ΄ λ³νμ§ μμ κ²μ΄λΌλ κ²μ μ΄λ―Έ μκ³ μμΌλ―λ‘ ng-ifμμλ ν λ² λ°μΈλ©μ μλνκ³ μΆμμ΅λλ€. ν λ² λ°μΈλ©μ μ¬μ©νμ§ μκ±°λ μ΄ κ²½μ° <p ng-if="::test.name && test.blah">testing with first expression as one time binded</p>
첫 λ²μ§Έ ννμμΌλ‘ ν λ²λ§ λ°μΈλ©μ μ¬μ©ν λ μλ²½νκ² μλνμ§λ§ λ€μκ³Ό κ²°ν©λ λ μ΄μμ ννμμμ ν λ² λ°μΈλ©μ μ¬μ©νλ €κ³ ν λ κ°λ μ°μ°μλ ꡬ문 μ€λ₯λ‘ μ€λ₯λ₯Ό λ°μμν΅λλ€.
Error: [$parse:syntax] Syntax Error: Token ':' not a primary expression at column 14 of the expression [test.name && ::test.blah && ::test.blah] starting at [::test.blah && ::test.blah].
http://errors.angularjs.org/1.3.14/$parse/syntax?
μ΄κ²μ λ²κ·Έμ λκΉ μλλ©΄ μ€μ ꡬ문 μ€λ₯μ λκΉ? angularjs λ²μ 1.3.14λ₯Ό μ¬μ©νκ³ μμ΅λλ€.
μ: <p ng-if="::(test.name && test.blah)">testing with first expression as one time binded</p>
ννμμ΄ μλ μ μ λ°μΈλ©μλ ()
λ₯Ό μ¬μ©ν΄μΌ νλ€κ³ μκ°ν©λλ€.
@piernik κ°μ¬λ 맀λ ₯μ²λΌ μλν©λλ€. (::test.name) && (::test.blah)
μλνμ§λ§ 첫 λ²μ§Έ ::
κ° ν λ² λ°μΈλ©μ νμ±ννλ κ² κ°μ΅λλ€. :+1:
μΌνμ± λ°μΈλ©(::)μ ng-if λ΄μμ μ¬μ©λλ λͺ¨λ ννμμ μ μ©λ©λλ€.
<p ng-if="::test.name && test.blah"> is same as <p ng-if="::(test.name && test.blah)">
λΆννλ μ°λ¦¬λ Angular jsμ λ¨μΌ ννμμμ μΌνμ± λ°μΈλ©κ³Ό λ¨λ°©ν₯ λ°μΈλ© ννμμ νΌν©ν μ μμ΅λλ€.
κ°μ₯ μ μ©ν λκΈ
μ:
<p ng-if="::(test.name && test.blah)">testing with first expression as one time binded</p>
ννμμ΄ μλ μ μ λ°μΈλ©μλ()
λ₯Ό μ¬μ©ν΄μΌ νλ€κ³ μκ°ν©λλ€.