javascript - AngularJS - 流默认值?

标签 javascript angularjs

我是 angularjs 的新手,在将输入字段的所有给定值“流式传输”到同一 html 文档的另一个位置时遇到了一些问题

例如:

<input type="text" name="headline" ng-model="headline"
class="form-control" placeholder="Your Headline"/> <-- No default value

在另一个地方:

<div class="header bg-blue preview">
     <h2 class="text-center">
              [[headline || "Your Headline"]]
     </h2>
</div>

这很完美。当我在输入字段中输入内容时,内容会立即传递到 .

我的问题是,如果输入字段已经有默认值,那么由于 ng-headline 而不会显示该默认值。

像这样:

<input type="text" name="headline" ng-model="headline"
class="form-control" placeholder="Your Headline" value="blablabla"/> <-- with default value

只要“ng-headline”在 中,“blabla”就不会显示在输入字段中。当我删除 ng-headline 时,该字符串在输入字段中显示为默认值。

我正在编写一个更新函数,“旧”数据应该已经作为值存在于输入字段中。输入字段旁边会显示更改的预览。这就是为什么我想使用 angular.js 将更改传递到预览。

最佳答案

Tr ng-value 或更好地尝试在 controller.js 文件本身内设置 $scope.headline

<input type="text" name="headline" ng-model="headline" class="form-control" placeholder="Your Headline" ng-value="blablabla"/>

关于javascript - AngularJS - 流默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50350253/

相关文章:

javascript - getElementbyId 的函数数组

javascript - Highcharts 在 Safari 和 Chrome 中的格式不同

javascript - 将 ng-init 与 ng-repeat 一起使用时覆盖

html - md-no-focus-style 在我的设置中无法正常工作

javascript - 参数 'PeopleController' 不是函数,未定义 IonicJS

php - 为什么我无法在 AngularJS、php 和 MySQL 上的项目上建立 session ?

javascript - Google Charts 上的多个实例

javascript - 在模态弹出窗口或标准弹出窗口中打开 Facebook Share

javascript - This.props.dispatch 不是一个函数 - React-Redux

javascript - CORS header 在浏览器中被剪切,状态代码 >= 400