如果我使用" +"则无法在文本框中编辑值ng模型中的运算符

时间:2016-09-27 10:54:42

标签: angularjs

我已经使用ng-init来初始化" firstName"的值。和"姓氏"。现在,如果我设置ng-model =" firstName"或ng-model =" lastName"然后我可以编辑文本框中的值。

但是如果我将ng-model设置为ng-model =" firstName + lastName"然后vales被映射,但我无法在文本框中编辑它。

为什么会这样?

 <div ng-app="" ng-init="firstName='John';lastName='Doe'">
 <p>Input something in the input box:</p>
 <p>Name: <input type="text" ng-model="firstName+lastName"></p>
 <p>You wrote: {{ firstName + lastName}}</p>
 </div>

1 个答案:

答案 0 :(得分:0)

您可以在HTML中执行类似的操作

    <Ribbon DockPanel.Dock="top">
            <RibbonTab Header="Home">
                <RibbonGroup Header="Process Flow">
                    <StackPanel Orientation="Horizontal">
                        <RibbonButton Label="Style change" LargeImageSource="pack://application:,,,/Resources/StyleChange.png"></RibbonButton>
                        <RibbonButton Label="Settings" Command="{Binding ChangeToSettingContentCommand}" LargeImageSource="pack://application:,,,/Resources/Settings.png"></RibbonButton>
                        <RibbonButton Label="Firmware changes" LargeImageSource="pack://application:,,,/Resources/Code.png"></RibbonButton>
                        <RibbonButton x:Name="testsButton" Label="Tests" Command="{Binding ChangeToTestContentCommand}" LargeImageSource="pack://application:,,,/Resources/test.png"></RibbonButton>
                    </StackPanel>
                </RibbonGroup>

只需在<div ng-init="firstName='John';lastName='Doe'"> <p>Input something in the input box:</p> <p>Name: <input type="text" ng-model="firstName"></p> <p>You wrote: {{ firstName + lastName}}</p> <p ng-init="fullname = firstName + lastName">Full Name: <input type="text" ng-model="fullname"></p> <p>You wrote: {{ fullname}}</p> </div> 中创建新的范围对象,否则您可以初始化JS中的范围对象,并将其作为ng-init显示在文本框中。