使用controller as语法时如何订阅属性更改?
controller('TestCtrl', function ($scope) {
this.name = 'Max';
this.changeName = function () {
this.name = new Date();
}
// not working
$scope.$watch("name",function(value){
console.log(value)
});
});
Run Code Online (Sandbox Code Playgroud)
<div ng-controller="TestCtrl as test">
<input type="text" ng-model="test.name" />
<a ng-click="test.changeName()" href="#">Change Name</a>
</div>
Run Code Online (Sandbox Code Playgroud) 当我创建视图主干时,如果未设置el,则创建空div容器.(this.$el.html(this.template(this.model.toJSON())))插入该div的模板.如何避免这个包装?我需要没有任何包装的干净模板,所以我可以将它插入我想要的任何地方?jobView.$e.children()用许多元素打电话是不合理的.
<script id="contactTemplate" type="text/html">
<div class="job">
<h1><%= title %>/<%= type %></h1>
<div><%= description %></div>
</div>
</script>
var JobView = Backbone.View.extend({
template:_.template($("#contactTemplate").html()),
initialize:function () {
this.render();
},
render:function () {
this.$el.html(this.template(this.model.toJSON()));
return this;
}
});
var jobView = new JobView({
model:jobModel
});
console.log(jobView.el);
Run Code Online (Sandbox Code Playgroud) 我可以将NgModelController传递给指令控制器吗?这是必需的,所以我可以为控制器中的模型赋值.
此示例不起作用:
angular
.module('directives.selectBox', [])
.directive('selectBox', selectBox);
function selectBox() {
return {
restrict : 'E',
require : 'ngModel',
scope : {
list : '=',
},
replace : true,
templateUrl : 'common/directives/selectBox/selectBox.html',
controller : SelectBoxController,
};
}
function SelectBoxController(ngModel) {
ngModel.$setViewValue(10); // ???
}
Run Code Online (Sandbox Code Playgroud) PHP 5.6
这段代码:
<?php
namespace Database
{
abstract class Model
{
}
}
namespace Models
{
use Database\Model as DbModel;
class Model extends DbModel
{
}
}
namespace Models
{
use Database\Model;
class Brand extends Model
{
}
}
namespace
{
$m = new \Models\Model();
}
Run Code Online (Sandbox Code Playgroud)
导致错误:
"致命错误:无法使用Database\Model作为模型,因为该名称已在第23行的D:\ OpenServer\domains\localhost\index.php中使用".
这段代码:
<?php
namespace Models
{
use Database\Model as DbModel;
class Model extends DbModel
{
}
}
namespace Models
{
use Database\Model;
class Brand extends Model
{
}
}
namespace Database
{ …Run Code Online (Sandbox Code Playgroud)