我在配置文件中使用另一个配置文件中的config var设置时遇到问题.例如
// file - config/local.js
module.exports = {
mongo_db : {
username : 'TheUsername',
password : 'ThePassword',
database : 'TheDatabase'
}
}
// file - config/connections.js
module.exports.connections = {
mongo_db: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
user: sails.config.mongo_db.username,
password: sails.config.mongo_db.password,
database: sails.config.mongo_db.database
},
}
Run Code Online (Sandbox Code Playgroud)
当我'航行升降机'时,我收到以下错误:
user: sails.config.mongo_db.username,
^
ReferenceError: sails is not defined
Run Code Online (Sandbox Code Playgroud)
我可以在其他地方访问配置变量 - 例如,这有效:
// file - config/bootstrap.js
module.exports.bootstrap = function(cb) {
console.log('Dumping config: ', sails.config);
cb();
}
Run Code Online (Sandbox Code Playgroud)
这会将所有配置设置转储到控制台 - 我甚至可以在那里看到mongo_db的配置设置!
我很困惑.
我需要在条目模板中输入几次条目.
所以我想从下面得到输出并分配给一个变量,这样我就可以在模板中重用:
{exp:channel:entries channel="product" limit="1" status="open"}
{categories}{category_name}{/categories}
{/exp:channel:entries}"
Run Code Online (Sandbox Code Playgroud)
怎么做?
我想在调试时将日志消息输出到控制台.在控制器中工作正常,但不能让它在模块配置块中工作,例如
angular.module('MyApp', [])
.run(function($state){
// run stuff here
});
.config(function($logProvider){
$log.debug('Config debug message');
});
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
error TypeError: Cannot read property 'debug' of undefined
Run Code Online (Sandbox Code Playgroud)
是否可以在模块的配置块中使用logProvider?
我正在使用带有Ionic的angular-google-places-autocomplete(https://github.com/kuhnza/angular-google-places-autocomplete)但在使用此指令时捕获所选选项时遇到问题.
我有这样的指令设置:
<!-- template -->
<input type="text" placeholder="Place search" g-places-autocomplete ng-model="locationSearchResult"/>
<h5>Result</h5>
<pre ng-bind="locationSearchResult | json"></pre>
Run Code Online (Sandbox Code Playgroud)
我的控制器代码设置为监视locationSearchResult模型的更改,如果它确实更改以将新位置保存到本地存储:
// Controller
$scope.locationSearchResult = {};
$scope.$watch('locationSearchResult', function(newVal, oldVal) {
if (angular.equals(newVal, oldVal)) { return; }
$scope.$storage.loc = newVal;
$state.go('new-page');
Run Code Online (Sandbox Code Playgroud)
});
当使用自动完成时,它似乎按预期工作 - 我得到一个预测列表,从预测列表中选择预测会使用所选位置的名称更新文本输入,并且所选位置的JSON数据显示在结果标题.但是,这个变化似乎并没有被$ scope.$ watch在控制器中看到.
因此,我似乎无法捕获搜索结果数据并对其执行任何操作 - 例如将其添加到用户会话中.
也许我只是以错误的方式去做(虽然我使用相同的方法与ngAutocomplete,它工作正常).
autocomplete google-places-api angularjs-directive ionic-framework